我有一项接受android.intent.action.SEND
的活动。
它接受一些媒体文件和文本。
因为它接受一个新的'share',它会进行一些验证检查并将Uri传递给服务,它看起来像这样:
Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
Intent serviceIntent = new Intent(this, ShareService.class)
.setData(uri)
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) // probably redundant but harmless here
.putParcelableArrayListExtra(Constants.EXTRA_SHARE_FILES, uris)
startService(serviceIntent);
它适用于所有file
提供商,通常也适用于content
,但我不时会收到失败报告:
Non-fatal Exception: java.lang.SecurityException: UID 10283 does not have permission to content://com.whatsapp.provider.media/item/33560 [user 0]
我有什么办法可以保持Uri的生存吗?我应该怎样处理这种Uri?
请在你的应用程序和xml提到的文件提供程序文件和网络安全配置文件中创建xml文件夹,然后在AndroidMenifest.xml文件中声明fileprovider