Say you have a method like this:
public boolean saveFile (Url url, String content) {
// save the file, this can be done a lot of different ways, but
// ba
You can Add a blocking helper method like this:
@TargetApi(23)
public static void checkForPermissionsMAndAboveBlocking(Activity act) {
Log.i(Prefs.TAG, "checkForPermissions() called");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// Here, thisActivity is the current activity
if (act.checkSelfPermission(
Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
// No explanation needed, we can request the permission.
act.requestPermissions(
new String[]{
Manifest.permission.WRITE_EXTERNAL_STORAGE
},
0);
while (true) {
if (act.checkSelfPermission(
Manifest.permission.WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED) {
Log.i(Prefs.TAG, "Got permissions, exiting block loop");
break;
}
Log.i(Prefs.TAG, "Sleeping, waiting for permissions");
try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); }
}
}
// permission already granted
else {
Log.i(Prefs.TAG, "permission already granted");
}
}
else {
Log.i(Prefs.TAG, "Below M, permissions not via code");
}
}