你的位置:首页 > 操作系统

[操作系统]android:exported对ContentProvider的影响

前两天按教学视频在MainActivity中写完ContentProvider后在Manifest中配置了如下代码

<provider  android:name="test.provider.SQLiteProvider"  android:authorities="test.provider" />

然而并不能传递内容,当时在网上找并没有找到明确答案,有的在provider配置了许多内容,偶然加上了一句android:exported="true" ,碰巧成功了,但是并不知道缘由。

今日细看SDK文档,发现端倪。

android:exportedWhether the content provider is available for other applications to use:true: The provider is available to other applications. Any application can use the provider's content URI to access it, subject to the permissions specified for the provider.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.The default value is "true" for applications that set either android:minSdkVersion or android:targetSdkVersion to "16" or lower. For applications that set either of these attributes to "17" or higher, the default is "false".You can set android:exported="false" and still limit access to your provider by setting permissions with the permission attribute.

据鄙人E渣的翻译,大意是最小SDK版本或者目标SDK版本小于等于16的,则默认值为“true”,else ,默认值为"false"。

由于教学视频为12年的,所以版本较老,而我用了最新的,不可避免产生差别。因此对于现在大部分人来说,是需要配置一下export较为妥当。

<provider  android:name="test.provider.SQLiteProvider"  android:authorities="test.provider"  android:exported="true" />