GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — AndroidTutorialForBeginners/permission.java at master · FiresideCode/AndroidTutorialForBeginners Expand file tree/ Copy pathpermission.javaMore file actions 88 lines (68 loc) · 3.04 KB / Copy pathpermission.javaFile metadata and controls88 lines (68 loc) · 3.04 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 //Sms Permiison /* <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.RECEIVE_SMS" /> */ //access to permsions void CheckUserPermsions(){ if ( Build.VERSION.SDK_INT >= 23){ if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED ){ requestPermissions(new String[]{ android.Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_CODE_ASK_PERMISSIONS); return ; } } getLastLocation();// init the contact list } //get acces to location permsion final private int REQUEST_CODE_ASK_PERMISSIONS = 123; @Override public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { switch (requestCode) { case REQUEST_CODE_ASK_PERMISSIONS: if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { getLastLocation();// init the contact list } else { // Permission Denied Toast.makeText( this,"your message" , Toast.LENGTH_SHORT) .show(); } break; default: super.onRequestPermissionsResult(requestCode, permissions, grantResults); } } //Get last location public void getLastLocation(){ LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); Location myLocation=locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (myLocation == null) { myLocation = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER); } } //read contact list public void getContactList(){ ArrayList<ListItem> list_contact=new ArrayList<ListItem>() ; Cursor cursor = getContentResolver().query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null,null, null); while (cursor.moveToNext()) { String name =cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)); String phoneNumber = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); list_contact.add(new ListItem(name, phoneNumber)); } } public class ListItem { public String Title; public String phoneNumber; public ListItem(String Title, String phoneNumber) { this. Title=Title; this. phoneNumber=phoneNumber; } } //ratinal permmison if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity, android.Manifest.permission.READ_CONTACTS)) { } |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |