是否可以将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( )).