如何使 FileProvider 可用于其他应用程序? [英] How can make a FileProvider available to other applications?

查看:119
本文介绍了如何使 FileProvider 可用于其他应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将 FileProvider 提供给其他应用程序?

Is it possible to have a FileProvider available to other applications ?

manifest.xml

manifest.xml

...
 <provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="com.example.myapp.fileprovider"
        android:exported="true"
        android:grantUriPermissions="false"
        android:permission="com.example.filesvisible.permission.READ" >
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/filespath" />
    </provider>
...

来自 doc:

false:该提供程序不可用于其他应用程序.放android:exported="false" 限制对提供者的访问应用程序.仅与具有相同用户 ID (UID) 的应用程序提供者将有权访问它.

false: The provider is not available to other applications. Set android:exported="false" to limit access to the provider to your applications. Only applications that have the same user ID (UID) as the provider will have access to it.

我尝试将导出设置为 true,但出现此异常无法获取提供者 android.support.v4.content.FileProvider: java.lang.SecurityException: Provider must not be export 为什么我不能导出 FileProvider ?

I've tried to set exported to true but I got this exception Unable to get provider android.support.v4.content.FileProvider: java.lang.SecurityException: Provider must not be exported Why I can't export a FileProvider ?

推荐答案

是否可以将 FileProvider 提供给其他应用程序?

Is it possible to have a FileProvider available to other applications ?

是的.这通常是重点.

为什么我不能导出 FileProvider ?

Why I can't export a FileProvider ?

因为这不是您使用 FileProvider 的方式.

Because that is not how you use a FileProvider.

FileProvider 背后的要点是 授予选择第三方应用访问文件的权限.您可以通过 FLAG_GRANT_READ_URI_PERMISSION 和/或 FLAG_GRANT_WRITE_URI_PERMISSION 在用于传递提供商的 Uri 之一的 Intent 中执行此操作code> 值到第三方应用程序(例如,通过 ACTION_VIEW IntentstartActivity() 一起使用).

The point behind FileProvider is to give select access to files to third-party apps. You can do this by FLAG_GRANT_READ_URI_PERMISSION and/or FLAG_GRANT_WRITE_URI_PERMISSION, in the Intent that you use to pass one of your provider's Uri values to the third-party app (e.g., via an ACTION_VIEW Intent used with startActivity()).

另请参阅有关共享文件的培训指南.

这篇关于如何使 FileProvider 可用于其他应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆