Androidアプリ:When using intent filters, please specify ‘android:exported’ as well
Android Studioで「When using intent filters, please specify ‘android:exported’ as well」というエラーメッセージが表示されたので調べました。
IntentFilterにおいてexportedを明示的に宣言する
この問題はAndroid12(SDK API31)以降のAndroidManifest.xmlファイルにおいて、android:exportedを設定していないときに表示されます。
Android11まではandroid:exprotedを宣言しなくても自動的に設定されるようになっていました。
AndroidManifest.xml内で、intent-filterを指定しているときに、そのActivityを外部アプリから呼び出せるようにするか否かの設定です。
android:exported=”true” → 外部アプリに公開する
android:exported=”false” → 外部アプリに公開しない
Android11までは、宣言がなければ、intent-fileterがある場合には、自動的に公開に設定されていましたが、Android12以降では明示的に公開にするか非公開にするかを指定しなければなりません。
exportedの宣言方法
基本的に外部アプリに公開するつもりなくつくっている場合には、非公開に設定しておきます。
<activity android:name=".MainActivity"
android:screenOrientation="portrait"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
関連記事