![](/img/trans.png)
[英]Android 6.0 (Marshmallow) Denying permissions and no Permission Request Dialog is shown to user
[英]Permission dialog is not being shown android marshmallow
我正在使用nexus 6 android 6.0,僅針對WRITE_EXTERNAL_STORAGE權限對話框未顯示其他危險權限。
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"
僅針對WRITE_EXTERNAL_STORAGE權限對話框未顯示其他危險權限
您的其他dangerous
許可是READ_EXTERNAL_STORAGE
。 在我們請求權限並檢查權限的同時,在Android 6.0 UI中,用戶會授予(或拒絕)權限組 。 READ_EXTERNAL_STORAGE
和WRITE_EXTERNAL_STORAGE
在同一組中。
因此,如果用戶先前已授予您對READ_EXTERNAL_STORAGE
的請求,則在您調用checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
時間點您已經擁有WRITE_EXTERNAL_STORAGE
checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.