private static final int REQUEST_EXTERNAL_STORAGE = 1;
private static String[] PERMISSIONS_STORAGE = {
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE};
/**
* 8 * Checks if the app has permission to write to device storage
* 9 *
* 10 * If the app does not has permission then the user will be prompted to
* 11 * grant permissions
* 12 *
* 13 * @param activity
* 14
*/
public static void verifyStoragePermissions(Activity activity) {
// Check if we have write permission
int permission = ActivityCompat.checkSelfPermission(activity,
Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (permission != PackageManager.PERMISSION_GRANTED) {
// We don't have permission so prompt the user
ActivityCompat.requestPermissions(activity, PERMISSIONS_STORAGE,
REQUEST_EXTERNAL_STORAGE);
}
}
博客
Androd color
03-09
102
博客
Android权限明细
01-12
216
12-08
227
11-04
563
11-04
401
11-04
2756
11-04
886
08-16
287
08-16
655
07-19
579
07-10
1485
07-09
3235
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交