Guest User

Untitled

a guest
Oct 23rd, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. public void ReadContactsPermission() {
  2. // Here, thisActivity is the current activity
  3. if (ContextCompat.checkSelfPermission(thisActivity,
  4. Manifest.permission.READ_CONTACTS)
  5. != PackageManager.PERMISSION_GRANTED) {
  6.  
  7. // Should we show an explanation?
  8. if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
  9. Manifest.permission.READ_CONTACTS)) {
  10.  
  11. // Show an explanation to the user *asynchronously* -- don't block
  12. // this thread waiting for the user's response! After the user
  13. // sees the explanation, try again to request the permission.
  14.  
  15. } else {
  16.  
  17. // No explanation needed, we can request the permission.
  18.  
  19. ActivityCompat.requestPermissions(thisActivity,
  20. new String[]{Manifest.permission.READ_CONTACTS},
  21. MY_PERMISSIONS_REQUEST_READ_CONTACTS);
  22.  
  23. // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
  24. // app-defined int constant. The callback method gets the
  25. // result of the request.
  26. }
  27. }
  28. }
  29.  
  30. // Show an explanation to the user *asynchronously* -- don't block
  31. // this thread waiting for the user's response! After the user
  32. // sees the explanation, try again to request the permission.
  33.  
  34. // Show an explanation to the user *asynchronously* -- don't block
  35. // this thread waiting for the user's response! After the user
  36. // sees the explanation, try again to request the permission.
  37. showExplanation()
  38. return ReadContactsPermission();
Add Comment
Please, Sign In to add comment