Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void checkWriteLocationPermissionFor23(Context context, int code){
- // Here, thisActivity is the current activity
- if (ContextCompat.checkSelfPermission(context,
- Manifest.permission.ACCESS_FINE_LOCATION)
- != PackageManager.PERMISSION_GRANTED) {
- // Should we show an explanation?
- if (ActivityCompat.shouldShowRequestPermissionRationale((Activity)context,
- Manifest.permission.ACCESS_FINE_LOCATION)) {
- // Show an expanation to the user *asynchronously* -- don't block
- // this thread waiting for the user's response! After the user
- // sees the explanation, try again to request the permission.
- } else {
- // No explanation needed, we can request the permission.
- ActivityCompat.requestPermissions((Activity)context,
- new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
- code);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement