In android M to access sdcard has to force stop and start app manually when permission is granted at runtime, how to achieve it programmatically?
However sdcard can be accessed if the app is force stop and restarted.
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);
}