標籤:
前兩天按教學視頻在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" />
android:exported對ContentProvider的影響