2016-11-07 132 views

回答

1

您需要創建權限的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); 
+0

我想通過使用方法onRequestPersmissionResult我有一個INT代碼 –

+0

@SonuKumar檢查http://stackoverflow.com/questions/34342816/android-6-0-multiple-permissions/35495855#35495855處理更多的權限 –