-3

I was able to handle dangerous permissions in android 6 using this line of code in my Activity :

    ActivityCompat.requestPermissions(WriteThreadActivity.this,
            new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE,
                    android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, RESULT_LOAD_IMAGE);

It works fine but is there anyway to prevent showing this popup every time user opens this activity? Somethings like remember method?

Payam Asefi
  • 2,677
  • 2
  • 15
  • 26

2 Answers2

1
// Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(thisActivity,
            Manifest.permission.WRITE_EXTERNAL_STORAGE)
    != PackageManager.PERMISSION_GRANTED) {

// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
        Manifest.permission.WRITE_EXTERNAL_STORAGE)) {

    // 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(thisActivity,
            new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
            MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);

    // MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE is an
    // app-defined int constant. The callback method gets the
    // result of the request.
}
}else{
  // You have permission granted already, to the task
}
John
  • 8,846
  • 8
  • 50
  • 85
  • You dont need to Request for READ_EXTERNAL_STORAGE permission if you request for WRITE_EXTERNAL_STORAGE as it is in the same Permission group, it will get access automatically. – John Dec 28 '15 at 06:11
0
private boolean doesUserHavePermission()
{
    int result = context.checkCallingOrSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
    return result == PackageManager.PERMISSION_GRANTED;
}
Nirav Shah
  • 67
  • 10