調用自定義 ContentProvider 進行增刪改查均報錯:
java.lang.SecurityException: Permission Denial: opening provider
com.dfby.sqlite.provider.PersonContentProvider from ProcessRecord...
that is not exported from uid 10062
AndroidManifest.xml 中 <provider> 標籤缺少 android:exported="true" 或缺少相應的 <permission> 聲明,導致跨進程訪問被系統阻擋。
<provider> 中添加 android:exported="true"(API 17+ 必須顯式聲明)。<permission android:name="com.dfby.PROVIDER_PERMISSION"
android:protectionLevel="normal" />
<provider
android:name=".provider.PersonContentProvider"
android:authorities="com.dfby.sqlite.provider"
android:exported="true"
android:readPermission="com.dfby.PROVIDER_PERMISSION"
android:writePermission="com.dfby.PROVIDER_PERMISSION" />
AndroidManifest.xml 添加 <uses-permission android:name="com.dfby.PROVIDER_PERMISSION" />。adb shell dumpsys package <pkg> 檢查 Provider 權限設置。ContentProvider 跨進程訪問必須在 Manifest 中正確配置 exported 與權限屬性,否則系統會拋出 SecurityException。