定制选择器活动:SecurityException UID n没有对content://uri的许可 [英] Custom chooser activity: SecurityException UID n does not have permission to content:// uri

查看:122
本文介绍了定制选择器活动:SecurityException UID n没有对content://uri的许可的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个Chooser应用程序,该应用程序将替换本机的Android Share对话框.除我尝试通过长按图像>共享图像从Chrome共享图像外,它都可以正常工作.

I'm building a Chooser app that replaces the native Android Share dialog. It works fine except when I try to share an image from Chrome via longpress image > share image.

我发现Google+没有捕获到异常(崩溃),因此我可以通过Logcat进行查看:

I found that Google+ doesn't catch the exception (it crashes) so I can have a look at it via Logcat:

  • 在Google上进行图片搜索.
  • 选择一张图片(这应该显示预览)
  • 长按图片
  • 选择共享图片"
  • 弹出我的选择器活动
  • 选择Google +
  • Google+因以下错误而崩溃:

java.lang.SecurityException:UID 10130没有对content://com.android.chrome.FileProvider/images/screenshot/15307295588677864462883877407218.jpg [user 0]的权限

java.lang.SecurityException: UID 10130 does not have permission to content://com.android.chrome.FileProvider/images/screenshot/15307295588677864462883877407218.jpg [user 0]

我的代码(简体):

@Override
public void onCreate() {
    handleIntent();
}

private void handleIntent() {

    // Get intent and payload
    mIntent = getIntent();
    mPayloadIntent = (Intent) mIntent.getParcelableExtra(Intent.EXTRA_INTENT);

    // Nullify some things for queryIntentActivities (or no results will be found)
    mPayloadIntent.setComponent(null);
    mPayloadIntent.setPackage(null);

    // Retrieve a list of targets we can send mPayloadIntent to..
    List<ResolveInfo> targets = context.getPackageManager().queryIntentActivities(mPayloadIntent, 0);
    // etc...

}

private void onClickTarget(ResolveInfo target) {

    // Prepare..
    ComponentName compName = new ComponentName(
                target.activityInfo.applicationInfo.packageName,
                target.activityInfo.name);

    // Build a 'new' shareIntent
    Intent shareIntent = new Intent(mPayloadIntent);
    shareIntent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT | Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP);
    shareIntent.setComponent(compName);

    // Start the targeted activity with the shareIntent
    startActivity(shareIntent);
    finish();

}

AndroidManifest.xml:

AndroidManifest.xml:

<activity
    android:name=".ActShareReplace"
    android:label="Sharedr"
    android:theme="@style/AppTheme.TransparentActivity"
    >
    <intent-filter>
        <action android:name="android.intent.action.CHOOSER" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

如果我查看 Intent.ACTION_CHOOSER

If I look at the documentation for Intent.ACTION_CHOOSER it says:

如果需要通过选择器授予URI权限,除了内部的EXTRA_INTENT之外,还必须指定要在ACTION_CHOOSER Intent上授予的权限.这意味着使用setClipData(ClipData)来指定要授予的URI以及相应的FLAG_GRANT_READ_URI_PERMISSION和/或FLAG_GRANT_WRITE_URI_PERMISSION.

If you need to grant URI permissions through a chooser, you must specify the permissions to be granted on the ACTION_CHOOSER Intent in addition to the EXTRA_INTENT inside. This means using setClipData(ClipData) to specify the URIs to be granted as well as FLAG_GRANT_READ_URI_PERMISSION and/or FLAG_GRANT_WRITE_URI_PERMISSION as appropriate.

我不确定这是我的应用程序必须执行的事情,还是调用选择器活动的应用程序的责任-但我认为是后者.我的应用无法为其接收的意图设置URI权限,可以吗?

I'm not completely sure if this is something my app has to do or if it's the responsibility of the app that invoked the chooser activity - but I would assume it's the latter. My app can't set URI permissions for intents it's receiving, can it?

无论如何,如果我检查mIntentmPayloadIntent上的多余符号和标志,则会得到:

Anyway, if I inspect the extra's and flags on mIntent and mPayloadIntent I get:

mIntent仅具有附加功能,没有标志(据我所知):

mIntent only has extras, no flags (as far as I can tell):

android.intent.extra.CHOSEN_COMPONENT_INTENT_SENDER IntentSender {4fa3901:android.os.BinderProxy@3aec3a6}(android.content.IntentSender)

android.intent.extra.CHOSEN_COMPONENT_INTENT_SENDER IntentSender{4fa3901: android.os.BinderProxy@3aec3a6} (android.content.IntentSender)

android.intent.extra.INTENT 意图{act = android.intent.action.SEND typ = image/jpeg flg = 0x80001 clip = {image/jpeg U:content://com.android.chrome.FileProvider/images/screenshot/15307316967108618905905323381238187.jpg}(有其他功能) )}(android.content.Intent)

android.intent.extra.INTENT Intent { act=android.intent.action.SEND typ=image/jpeg flg=0x80001 clip={image/jpeg U:content://com.android.chrome.FileProvider/images/screenshot/15307316967108618905323381238187.jpg} (has extras) } (android.content.Intent)

android.intent.extra.TITLE 通过(java.lang.String)共享

android.intent.extra.TITLE Share via (java.lang.String)

mPayloadIntent:

mPayloadIntent:

android.intent.extra.STREAM content://com.android.chrome.FileProvider/images/screenshot/1530731945132897653908815339041.jpg(android.net.Uri $ HierarchicalUri)

android.intent.extra.STREAM content://com.android.chrome.FileProvider/images/screenshot/1530731945132897653908815339041.jpg (android.net.Uri$HierarchicalUri)

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆