android:exported對ContentProvider的影響

來源:互聯網
上載者:User

標籤:

前兩天按教學視頻在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的影響

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.