在Android M中,当权限在运行时被授予时,访问SD卡需要手动停止和启动应用程序,如何以编程方式实现?
但是,如果强制停止并重新启动应用程序,则可以访问SD卡。
AndroidManifest.xml:
但是,如果强制停止并重新启动应用程序,则可以访问SD卡。
AndroidManifest.xml:
uses-permission-sdk-m android:name="android.permission.WRITE_EXTERNAL_STORAGE
/* **Checking permission **
if doesn't have request
else
browse file directory
*/
String[] perm = { Manifest.permission.WRITE_EXTERNAL_STORAGE };
if (checkSelfPermission(perm[0]) == PackageManager.PERMISSION_DENIED) {
requestPermissions(perm, REQ);
} else {
Explore(); //method to browse file directory
}
onRequestPermissionsResult
@Override
public void onRequestPermissionsResult(int requestCode,
String[] permissions, int[] grantResults) {
// TODO Auto-generated method stub
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
//Not able to browse SD card until restart application
Explore(); //method to browse file directory
} else {
Log.i("onRequestPermissionsResult", " Request denied");
}
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}