Last active
August 13, 2016 11:05
Android - Request Multiple Permissions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> | |
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | |
<permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | |
<permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// check for permissions | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | |
requestMultiplePermissions(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@TargetApi(Build.VERSION_CODES.M) | |
private void requestMultiplePermissions() { | |
// init permissions list | |
List<String> permissions = new ArrayList<>(); | |
String[] permissionsList = new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}; | |
// loop through permissions | |
for (String permission : permissionsList){ | |
if (checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) { | |
permissions.add(permission); | |
} | |
} | |
// if permissions list is not empty, request permission | |
if (!permissions.isEmpty()) { | |
requestPermissions(permissions.toArray(new String[permissions.size()]), Global.REQUEST_ALL_PERMISSIONS); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment