1

在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)

我的 android 清单权限

<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"/>
4

3 回答 3

0

您是否声明了许可?

<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
     }
  }
}
于 2016-03-01T11:32:35.207 回答
0

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

于 2016-03-01T11:34:41.240 回答
0

我遇到过同样的问题。使用从图库中选择图像后,图像显示在 Imageview 中

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;
}
于 2018-04-20T06:22:36.687 回答