使用FileProvider打开带有android默认应用程序的图像(InternalStorage)

时间:2014-07-16 18:21:03

标签: java android android-intent android-contentprovider

我有一张存储在我的内部应用程序存储中的图片,我想用android默认应用程序(图库或任何其他)打开它。

所以我使用的是FileProvider,我的代码在android 4.3上工作正常,但在某些版本(例如2.3.6)上,它不起作用,应用程序打开自己但是然后是黑屏,没什么。 我的应用需要兼容API-10

我阅读了许多与此问题相关的主题,似乎没有什么可以修复的。代码可能没错,因为它适用于4.3 ...... 有什么想法吗?

启动活动的代码:

File file = getMyFile();
Uri contentUri = FileProvider.getUriForFile(getContext(), <full-path-to-my-activity>, file);

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(contentUri, "image/*");
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent = Intent.createChooser(intent, "Open with");

startActivity(intent);

在我的清单中:

<provider
    android:name="android.support.v4.content.FileProvider"
    android:authorities="<full-path-to-my-activity>"
    android:exported="false"
    android:grantUriPermissions="true">
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/provider"/>
</provider>

我的provider.xml:

<?xml version="1.0" encoding="utf-8"?>
<paths>
<files-path
    name="pictures"
    path=""/>
</paths>

0 个答案:

没有答案