图像没有加载到某些手机中,说 SecurityException PermissionDeny in Android 中



在Android中,我试图从存储其URI的图库中获取图像,然后将其拉回,但它显示SecurityException。请帮助我。谢谢

ImageView: Unable to open content: content://com.google.android.apps.photos.contentprovider/-1/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F70/NO_TRANSFORM/908138224
                                                                           java.lang.SecurityException: Permission Denial: opening provider com.google.android.apps.photos.contentprovider.MediaContentProvider from ProcessRecord{12795c7f 18283:dccenter.dccenter.com.dccenter/u0a162} (pid=18283, uid=10162) that is not exported from uid 10106
                                                                               at android.os.Parcel.readException(Parcel.java:1546)
                                                                               at android.os.Parcel.readException(Parcel.java:1499)
                                                                               at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:3833)
                                                                               at android.app.ActivityThread.acquireProvider(ActivityThread.java:6084)
                                                                               at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:3178)
                                                                               at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1495)
                                                                               at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1115)
                                                                               at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:970)
                                                                               at android.content.ContentResolver.openInputStream(ContentResolver.java:695)
                                                                               at android.widget.ImageView.resolveUri(ImageView.java:784)
                                                                               at android.widget.ImageView.setImageURI(ImageView.java:440)
                                                                               at adapter.SlidingImageAdapter.instantiateItem(SlidingImageAdapter.java:118)

我的安卓清单权限

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.apps.photos.permission.GOOGLE_PHOTOS" />
<uses-permission android:name="android.permission.READ_USER_DICTIONARY" />
<uses-permission android:name="android.permission.READ_USER_DICTIONARY" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS"/>

你声明了权限吗?

<uses-permission android:name="android.permission.MANAGE_DOCUMENTS"/>

如果没有,这里有一个简单的解决方案:

public static final String KITKAT_VALUE = 1002;
  Intent intent;
    if (Build.VERSION.SDK_INT < 19){
                            intent = new Intent();
                            intent.setAction(Intent.ACTION_GET_CONTENT);
                            intent.setType("image/*");
                            startActivityForResult(intent, KITKAT_VALUE);
                        } else {
                            intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
                            intent.addCategory(Intent.CATEGORY_OPENABLE);
                            intent.setType("image/*");
                            startActivityForResult(intent, KITKAT_VALUE);
                    }
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
   if (requestCode == KITKAT_VALUE ) {
     if (resultCode == Activity.RESULT_OK) {
       // do something here
     }
  }
}
棉花

糖中的这个问题可以通过将目标设置为 22 或更少来解决此问题或支持运行时权限。看看这篇博文 : [链接] http://inthecheesefactory.com/blog/things-you-need-to-know-about-android-m-permission-developer-edition/en

我遇到了同样的问题。使用 从库中选取图像后,图像视图中显示的图像

Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, videoIdentifier);

并从 URI 解码位图图像

但是保存 URI 以供将来使用并重新打开应用程序并重用保存的 URI 不起作用。无法从 URI 解码位图。

我通过从 URI 路径中提取原始内容 uri 解决了这个问题

public String RemoveUnwantedString(String pathUri){
    //pathUri = "content://com.google.android.apps.photos.contentprovider/-1/2/content://media/external/video/media/5213/ORIGINAL/NONE/2106970034"
    String[] d1 = pathUri.split("content://");
    for (String item1:d1) {
        if (item1.contains("media/")) {
            String[] d2 = item1.split("/ORIGINAL/");
            for (String item2:d2) {
                if (item2.contains("media/")) {
                    pathUri = "content://" + item2;
                    break;
                }
            }
            break;
        }
    }
    //pathUri = "content://media/external/video/media/5213"
    return pathUri;
}

相关内容

  • 没有找到相关文章

最新更新