1
我想知道如何在單個請求上添加多個權限。這是關於android的棉花糖版本。如何在權限請求中添加多個權限
我想知道如何在單個請求上添加多個權限。這是關於android的棉花糖版本。如何在權限請求中添加多個權限
您需要創建權限的ArrayList需要
List<String> permissionsNeeded = new ArrayList<String>();
final List<String> permissionsList = new ArrayList<String>();
if (!addPermission(permissionsList, Manifest.permission.READ_PHONE_STATE))
permissionsNeeded.add("android.permission.READ_PHONE_STATE");
if (!addPermission(permissionsList, Manifest.permission.WRITE_EXTERNAL_STORAGE))
permissionsNeeded.add("android.permission.WRITE_EXTERNAL_STORAGE");
// addPermission
private boolean addPermission(List<String> permissionsList, String permission) {
if (ContextCompat.checkSelfPermission(LoginActivity.this, permission) != PackageManager.PERMISSION_GRANTED) {
permissionsList.add(permission);
// Check for Rationale Option
if (!ActivityCompat.shouldShowRequestPermissionRationale(LoginActivity.this, permission))
return false;
}
return true;
}
同樣加入數組列表所有權限。
// now request permission
ActivityCompat.requestPermissions(context,
permissionsList.toArray(new String[permissionsList.size()]),
PERMISSIONS_REQUEST_CODE);
我想通過使用方法onRequestPersmissionResult我有一個INT代碼 –
@SonuKumar檢查http://stackoverflow.com/questions/34342816/android-6-0-multiple-permissions/35495855#35495855處理更多的權限 –