ContentProviderを使ってデータを取得しようとしてエラーに引っかかってしまい時間をとられた
java.lang.IllegalArgumentException: Unknown authority com.sample.content.provider.testprovider
at android.content.ContentResolver.call(ContentResolver.java:2402)
at com.sample.content.client.MainActivity.loadText(MainActivity.kt:27)
at com.sample.content.client.MainActivity.onCreate$lambda-0(MainActivity.kt:17)
at com.sample.content.client.MainActivity.lambda$9zIV18Q6InENemqclwLnyzJ6Kg8(Unknown Source:0)
at com.sample.content.client.-$$Lambda$MainActivity$9zIV18Q6InENemqclwLnyzJ6Kg8.onClick(Unknown Source:2)
at android.view.View.performClick(View.java:7448)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1119)
at android.view.View.performClickInternal(View.java:7425)
at android.view.View.access$3600(View.java:810)
at android.view.View$PerformClick.run(View.java:28305)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7710)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1093)
呼び出す側のアプリのAndroidManifest.xmlで使用するアプリのパッケージ名(ContentProviderのauthorityではない)を明記しておく必要があった
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sample.content.client">
<queries>
<package android:name="com.sample.content.provider" />
</queries>
<application
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Main">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
この記事によるとAndroid11で発生する模様
https://www.jianshu.com/p/631148c98ac2