Got*_*ode 5 android android-fileprovider
我试图通过摆脱FileUriExposedException来支持Nougat.当我使用Uri.fromFile(gettheImageFilehere())方法我成功获取图像路径文件:///storage/emulated/0/DCIM/Camera/IMG_20170308_171951.jpg
当我使用
FileProvider.getUriForFile(HomeView.this, getApplicationContext().getPackageName() + ".provider",
gettheImageFilehere());
Run Code Online (Sandbox Code Playgroud)
我得到的图像路径为:/external_files/DCIM/Camera/IMG_20170308_171951.jpg
我试图使用android.os.FileUriExposedException上提供的实现. 这是我在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>
Run Code Online (Sandbox Code Playgroud)
然后我在res/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>
Run Code Online (Sandbox Code Playgroud)
我对上述情况表示怀疑:
我得到的完整错误是无法解码流:java.io.FileNotFoundException:/ external_files/DCIM/Camera/IMG_20170308_175833.jpg(没有这样的文件或目录)
代码段的.java文件是在这里查看我的实现.
小智 0
尝试使用
Intent iGallery = new Intent(Intent.ACTION_PICK,MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
| 归档时间: |
|
| 查看次数: |
481 次 |
| 最近记录: |