Android FileProvider 应用间共享媒体资源

目录

0. 重要参考文档

1. FileProviderSender

1.1  AndoroidManifest 添加provider声明

 1.2 根据文件创建Uri, 并作为Intent 的extra, 然后启动FileProviderReceiver

2. FileProviderReceiver

2.1 布局文件

2.2 根据Uri 读取图片

3. 效果图

3.1 发送方

3.2 接收方


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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值