android – 如何使FileProvider可用于其他应用程序?

是否可以将FileProvider用于其他应用程序?

的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: 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:不能导出提供程序为什么我无法导出FileProvider?

解决方法

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

是.这通常就是重点.

Why I can’t export a FileProvider ?

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

FileProvider背后的点是give select access to files to third-party apps.您可以通过FLAG_GRANT_READ_URI_PERMISSION和/或FLAG_GRANT_WRITE_URI_PERMISSION在用于将您的提供者的Uri值之一传递给第三方应用程序的Intent中执行此操作(例如,通过与startActivity一起使用的ACTION_VIEW Intent( )).

另见the training guide on sharing files.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...