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

前端之家收集整理的这篇文章主要介绍了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背后的点是@L_301_1@.您可以通过FLAG_GRANT_READ_URI_PERMISSION和/或FLAG_GRANT_WRITE_URI_PERMISSION在用于将您的提供者的Uri值之一传递给第三方应用程序的Intent中执行此操作(例如,通过与startActivity一起使用的ACTION_VIEW Intent( )).

另见the training guide on sharing files.

原文链接:https://www.f2er.com/android/316081.html

猜你在找的Android相关文章