2015-10-06 92 views
1

即時通訊使用nexus 6 android 6.0,只爲WRITE_EXTERNAL_STORAGE權限對話框不顯示其他危險的權限,它顯示。權限對話框不顯示android棉花糖

final private int REQUEST_CODE_ASK_PERMISSIONS = 123; 

@TargetApi(Build.VERSION_CODES.M) 
private void insertDummyContactWrapper() { 
    int hasWriteContactsPermission = checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE); 

    // Here, thisActivity is the current activity 
    if (hasWriteContactsPermission != PackageManager.PERMISSION_GRANTED) { 

     // Should we show an explanation? 
     if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, 
       Manifest.permission.WRITE_EXTERNAL_STORAGE)) { 

      // Show an expanation to the user *asynchronously* -- don't block 
      // this thread waiting for the user's response! After the user 
      // sees the explanation, try again to request the permission. 

     } else { 

      // No explanation needed, we can request the permission. 

      ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 
        110); 

      // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an 
      // app-defined int constant. The callback method gets the 
      // result of the request. 
     } 
    } 
} 

體形:

defaultConfig { 
     applicationId "com.example.application" 
     minSdkVersion 16 
     targetSdkVersion 23 
     versionCode 1 
     versionName "1.0" 
    } 

清單:

uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" 
uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" 
+0

試試這可能是工作http://stackoverflow.com/a/41221852/5488468 –

+0

你有沒有找到解決方案的運氣? – Dogcat

回答

2

僅供WRITE_EXTERNAL_STORAGE權限對話框不顯示其他危險允許它顯示

您的其他dangerous權限爲READ_EXTERNAL_STORAGE。雖然我們要求權限並檢查權限,但在Android 6.0用戶界面中,用戶授予(或拒絕)權限READ_EXTERNAL_STORAGEWRITE_EXTERNAL_STORAGE處於同一組中。

因此,如果用戶以前授予您對READ_EXTERNAL_STORAGE的請求,那麼在撥打checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);時您已經有WRITE_EXTERNAL_STORAGE