意向显示空白图像 [英] Intent shows a blank image
本文介绍了意向显示空白图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我尝试使用intent打开图库(我正在开发文件管理器)上的图像时,显示的图像完全是黑色的.但是我不明白为什么,因为我也遵循了最后的最佳做法谷歌关于获取Uri(与FileProvider一起使用)的实践.
When i try to open an image on the gallery (I'm developing a file manager) using intent, the image shown is totally black., but I can't understand why, as I've also followed the last best practices by google about getting the Uri (with FileProvider).
MainActivity.java
MainActivity.java
Intent intent=new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri uri=FileProvider.getUriForFile(MainActivity.this,BuildConfig.APPLICATION_ID + ".provider",image);
intent.setDataAndType(uri,MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileName));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
AndroidManifest.xml
AndroidManifest.xml
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
</application>
provider_paths.xml
provider_paths.xml
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="."/>
</paths>
推荐答案
更改:
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
收件人:
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_GRANT_READ_URI_PERMISSION);
目前,其他应用无权查看Uri
标识的图像.
as right now, the other app has no rights to view the image identified by the Uri
.
这篇关于意向显示空白图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文