Advertisement
vergepuppeter

Util.CheckLocation

Jun 15th, 2016
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.05 KB | None | 0 0
  1.  public static void checkWriteLocationPermissionFor23(Context context, int code){
  2.         // Here, thisActivity is the current activity
  3.         if (ContextCompat.checkSelfPermission(context,
  4.                 Manifest.permission.ACCESS_FINE_LOCATION)
  5.                 != PackageManager.PERMISSION_GRANTED) {
  6.  
  7.             // Should we show an explanation?
  8.             if (ActivityCompat.shouldShowRequestPermissionRationale((Activity)context,
  9.                     Manifest.permission.ACCESS_FINE_LOCATION)) {
  10.  
  11.                 // Show an expanation 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((Activity)context,
  20.                         new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
  21.                         code);
  22.  
  23.             }
  24.         }
  25.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement