本文介绍了Android:java.lang.SecurityException:无权访问uri 0 @ content://com.android.chrome.FileProvider/BlockedFile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个包含活动的App,该活动可以通过android.intent.action.CHOOSERandroid.intent.action.SEND动作调用.

I'm developing an App which contains an Activity that can be invoked via the android.intent.action.CHOOSER and android.intent.action.SEND actions.

当我通过Chrome共享网站以进行此活动时,我可以通过Uri uriScreenshot = bExtras.getParcelable("share_screenshot_as_stream");检索网站的屏幕截图,然后将该流存储到位图中.我存储它并没有什么关系,但是重要的是,该流存在于调用我的Activity的Intent中.

When I share a website via Chrome to this activity, I can retrieve the screenshot of the website via Uri uriScreenshot = bExtras.getParcelable("share_screenshot_as_stream"); and then store that stream into a Bitmap. It's not really relevant that I'm storing it, but what's important is that this stream exists in the Intent that invoked the my Activity.

有时我想转发"该Intent,让Android向用户显示系统的共享"对话框.为此,我修改了Intent,将Intent直接指向Android的内部Chooser:

Sometimes I want to "reshare" that Intent, have Android show the user the system's share dialog. In order to do this I modify the Intent, pointing the Intent directly to Android's internal Chooser:

iCurrentIntent.setClassName("android", "com.android.internal.app.ChooserActivity");
MyApplication.getAppContext().startActivity(iCurrentIntent);

我的问题是出现以下异常:

My problem is that I get the following exception:

E/AndroidRuntime: FATAL EXCEPTION: main
  Process: process.name.abc.xyz, PID: 29696
  java.lang.SecurityException: Uid 10107 does not have permission to uri 0 @ content://com.android.chrome.FileProvider/BlockedFile_101125595074498
     at android.os.Parcel.readException(Parcel.java:1684)
     at android.os.Parcel.readException(Parcel.java:1637)
     at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:3101)
     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1518)
     at android.app.ContextImpl.startActivity(ContextImpl.java:791)
     at android.app.ContextImpl.startActivity(ContextImpl.java:768)
     at android.content.ContextWrapper.startActivity(ContextWrapper.java:356)
     at process.name.abc.xyz.managers.utils.MyReshareManager.reshare(MyReshareManager.java:155)
     at process.name.abc.xyz.services.HUDService$HUDManager$11.onClick(HUDService.java:695)
     at android.view.View.performClick(View.java:5637)
     at android.view.View$PerformClick.run(View.java:22429)
     at android.os.Handler.handleCallback(Handler.java:751)
     at android.os.Handler.dispatchMessage(Handler.java:95)
     at android.os.Looper.loop(Looper.java:154)
     at android.app.ActivityThread.main(ActivityThread.java:6121)
     at java.lang.reflect.Method.invoke(Native Method)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)

问题不在于我正在修改Intent,而是我相信,当Android调用我的Activity时,我在Bitmap流上分配了一些安全权限,而当我转发Intent时,我正在接受该Activity( com.android.internal.app.ChooserActivity)没有读取该流的权限,因为它是授予我的应用程序的,而不是授予com.android.internal.app.ChooserActivity的.

The issue is not that I am modifying the Intent, but, I believe, the fact that I am getting assigned some security permissions on the Bitmap stream when Android invokes my Activity, and that when I forward the Intent the recieving Activity (com.android.internal.app.ChooserActivity) doesn't have permission to read that stream, since it was granted to my app and not to com.android.internal.app.ChooserActivity.

我尝试将iCurrentIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);添加到该意图中,但这不能解决问题.

I have tried adding iCurrentIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); to the intent, but that doesn't solve the issue.

显然与意图包含ChooserActivity试图访问的流有关.如果不存在此类流,则不会发生该问题.

It is clearly related to the fact that the intent contains a stream which the ChooserActivity is trying to access. If such a stream is not present, that problem does not occur.

当我尝试将Intent发送到Pocket iCurrentIntent.setClassName("com.ideashower.readitlater.pro", "com.ideashower.readitlater.activity.AddActivity");时,也会发生这种情况;实际上,任何接收活动(Twitter,WhatsApp).

This also occurs when I try to send that Intent over to Pocket iCurrentIntent.setClassName("com.ideashower.readitlater.pro", "com.ideashower.readitlater.activity.AddActivity");; in fact, any receiving Activity (Twitter, WhatsApp).

总是相同的UID 10107试图访问流并导致崩溃,这有点奇怪,因为它看起来不是导致崩溃的接收方Activity.我之所以这样说,是因为如果我理解正确,Twitter和WhatsApp和ChooserActivity都具有不同的UID.

It's always that same UID 10107 which is trying to access the stream and causes the crash, which is a bit strange, because it makes it appear that it is not the receiving Activity which is causing the crash. I say so, because if I understood it correctly, Twitter and WhatsApp and ChooserActivity all have a different UID.

对此我该怎么办?

=========

=========

更新:看起来这与Chrome发送的ClipData有关,与流无关.正在努力.

Update: It looks like this is related to ClipData which Chrome is sending along, and not the stream. Working on it.

推荐答案

我得到了这个消息(不是专门由于chrome引起的),因为我从另一个应用程序复制/粘贴了意图构建代码.

I was getting this (not specifically due to chrome, however) because I copy/pasted intent-building code from another application.

具体地说,我有

uriToSend = FileProvider.getUriForFile(ctx, "com.mycompany.myfirstapp.fileprovider", f);

已复制到"com.mycompany.mysecondapp"中.因此,当mysecondapp尝试与"com.mycompany.myfirstapp.fileprovider"中的文件提供程序进行对话时,它试图与myfirstapp的无权访问的文件提供程序进行对话.

Copied into "com.mycompany.mysecondapp". So when mysecondapp tried to talk to the file provider at "com.mycompany.myfirstapp.fileprovider", it was trying to talk to myfirstapp's fileprovider, which it didn't have access to.

检查是否要发送到自己的文件提供程序:

Checklist if you're sending to your own fileprovider:

  1. 您已将fileprovider添加到Android清单
  2. 您的代码引用了您应用中fileprovider的URI

这篇关于Android:java.lang.SecurityException:无权访问uri 0 @ content://com.android.chrome.FileProvider/BlockedFile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 10:17