目录
1.1 AndoroidManifest 添加provider声明
1.2 根据文件创建Uri, 并作为Intent 的extra, 然后启动FileProviderReceiver
0. 重要参考文档
先参考以下两个文档:
官网介绍:https://developer.android.google.cn/training/data-storage/use-cases
TX 介绍:https://developers.weixin.qq.com/community/develop/doc/0004886026c1a8402d2a040ee5b401
然后基于以上的文档做一个例子介绍:
从FileProviderSender Apk共享一张保存在 应用专属空间 (Android/data/...) 的图片,
到FileProviderReciever apk中。
1. FileProviderSender
1.1 AndoroidManifest 添加provider声明
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.fileprovidersender">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.FileProviderSender">
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- android:grantUriPermissions="true" -->
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.example.fileprovidersender.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_provider_paths" />
</provider>
</application>
</manifest>
主要为 <provider > </provider> 标签内的, 具体介绍参考上面的两个文档链接。
特别需要注意 的是, android:grantUriPermission