这是处理权限的新方法的结果。您的应用程序现在需要获得运行时权限并准备好被拒绝。
在你的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