情景:1、A,B兩個程序,A程序提供ContentProvider;B程序訪問A程序的ContendProvider
2、在A程序中已經添加權限:
<provider android:name=".provider.UserProvider" android:authorities="com.example.listview.userprovider"></provider>
問題:A程序部署后,再運行B程序,報錯:
03-11 21:48:38.336: E/AndroidRuntime(2035): Caused by: java.lang.SecurityException: Permission Denial: opening provider com.example.listview.provider.UserProvider from ProcessRecord{4190d088 2035:com.example.callcontentprovider/u0a10053} (pid=2035, uid=10053) that is not exported from uid 10052
解決:
在A程序的清單文件中provider組件注冊沒有添加被外部調用的屬性,完整provider在清單文件中注冊如下:
<provider android:exported="true" android:name=".provider.UserProvider" android:authorities="com.example.listview.userprovider"></provider>