Request runtime permission for WRITE_EXTERNAL_STORAGE
Originally implemented by Erlkoenig90 (#244) but lost during the api split.
This commit is contained in:
parent
0e04c1a849
commit
12148f6a5d
2 changed files with 17 additions and 12 deletions
|
@ -38,7 +38,7 @@ import androidx.core.os.EnvironmentCompat;
|
|||
|
||||
import btools.router.OsmNodeNamed;
|
||||
|
||||
public class BRouterActivity extends Activity {
|
||||
public class BRouterActivity extends Activity implements ActivityCompat.OnRequestPermissionsResultCallback {
|
||||
|
||||
private static final int DIALOG_SELECTPROFILE_ID = 1;
|
||||
private static final int DIALOG_EXCEPTION_ID = 2;
|
||||
|
@ -670,15 +670,6 @@ public class BRouterActivity extends Activity {
|
|||
mWakeLock.release();
|
||||
}
|
||||
|
||||
public boolean checkSelfPermission (Context context, String perm ) {
|
||||
boolean b = checkSelfPermission(context, perm);
|
||||
if (b) {
|
||||
ActivityCompat.requestPermissions (this, new String[]{perm}, 0);
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
private String getStorageState(File f) {
|
||||
return EnvironmentCompat.getStorageState(f); //Environment.MEDIA_MOUNTED
|
||||
}
|
||||
|
@ -728,4 +719,15 @@ public class BRouterActivity extends Activity {
|
|||
}
|
||||
return isWritable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult (int requestCode, String[] permissions, int[] grantResults) {
|
||||
if (requestCode == 0) {
|
||||
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
mBRouterView.startSetup(null, true);
|
||||
} else {
|
||||
mBRouterView.init();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,6 +38,9 @@ import android.view.View;
|
|||
import android.widget.Toast;
|
||||
|
||||
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import btools.expressions.BExpressionContextWay;
|
||||
import btools.expressions.BExpressionMetaData;
|
||||
import btools.mapaccess.OsmNode;
|
||||
|
@ -176,9 +179,9 @@ public class BRouterView extends View
|
|||
}
|
||||
|
||||
if ( !td.isDirectory() ) {
|
||||
if ( ( (BRouterActivity) getContext() ).checkSelfPermission (getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
||||
// if (ContextCompat.checkSelfPermission (getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) {
|
||||
if (ContextCompat.checkSelfPermission (getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) {
|
||||
retryBaseDir = baseDir;
|
||||
ActivityCompat.requestPermissions ((BRouterActivity) getContext(), new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0);
|
||||
} else {
|
||||
( (BRouterActivity) getContext() ).selectBasedir( ( (BRouterActivity) getContext() ).getStorageDirectories (), guessBaseDir(), "Cannot access " + baseDir.getAbsolutePath () + "; select another");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue