這是處理權限的新方法的結果。您的應用程序現在需要獲得運行時權限並準備好被拒絕。
在你的onCreate(或地方),你檢查,並可能要求許可:
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.READ_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(this,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
MY_PERMISSIONS_REQUEST_READ_MEDIA);
// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
// app-defined int constant. The callback method gets the
// result of the request.
}
}
然後準備好接受這樣的權限:
@Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
switch (requestCode) {
case MY_PERMISSIONS_REQUEST_READ_MEDIA: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
} else {
// permission denied, boo! Disable the
// functionality that depends on this permission.
}
return;
}
}
}
來源
2015-10-15 11:26:33
Ben
我面臨着同樣的問題。我試圖將視頻上傳到Youtube,但我得到了同樣的錯誤。你找到解決方案嗎? – TOP
不是。我注意到,當我用WhatsApp拍照時,在聊天中,我可以在LogCat中看到同樣的錯誤。所以也許這是一個Android 6的問題,因爲新的運行時權限.... –
我試圖添加標誌Intent.FLAG_GRANT_READ_URI_PERMISSION,但它似乎無法正常工作。 – TOP