我试图用文件提供打开在牛轧糖中的一个文件牛轧糖打开文件,看到一些例子,并添加提供程序来体现和创造的providerpath 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>
provider_path .XML
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path
name="/"
path="." />
</paths>
代码打开文件:
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File(path);
MimeTypeMap mime = MimeTypeMap.getSingleton();
String ext = file.getName().substring(file.getName().indexOf(".") + 1);
String type = mime.getMimeTypeFromExtension(ext);
Log.d(TAG, file.getAbsolutePath() + "mime " + type + " ext " + ext + "uri file " + FileProvider.getUriForFile(context,
BuildConfig.APPLICATION_ID + ".provider",
file).toString());
Uri ur = UriHelper.getNougatUri(file);
Log.d(TAG, "uri2 " + ur);
intent.setDataAndType(FileProvider.getUriForFile(context,
BuildConfig.APPLICATION_ID + ".provider",
file), type);
context.startActivity(intent);
logcat的:
08-09 12:04:39.728 18288-18288/com.app.tod D/ChatAdapter1: /storage/emulated/0/com.app.tod/Media/sent/08-09-2017 12:04 PM.jpegmime image/jpeg ext jpeguri file content://com.app.tod.provider/%2Fstorage%2Femulated%2F0%2Fcom.app.tod%2F/com.app.toado/Media/sent/08-09-2017%2012%3A04%20PM.jpeg
08-09 12:04:39.729 18288-18288/com.app.tod D/ChatAdapter1: uri2 content://com.app.tod.provider/storage/emulated/0/com.app.tod/Media/sent/08-09-2017 12:04 PM.jpeg
当我在文件上点击进入画廊,并说图片无法加载, 图像在这个路径 - 存在
/storage/emulated/0/com.app.tod/Media/sent/08-09-2017 12:04 PM.jpeg
可有人请告诉我如何可以访问所有我为我的应用程序创建的文件夹中的文件位于/storage/emulated/0/com.app.tod/
另外,如果我想在内部存储的其他位置打开文件,有没有办法?
谢谢。
只需使用'ContentResolver' API获取'Uri'内容 – pskink
@pskink可以请给我一些链接或一些代码在我的情况下如何做到这一点? – Ghanendra
@pskink我也不想打开JPEG或视频文件,我也想打开文件,如PDF等 – Ghanendra