Android API31中android:exported属性的明确使用准则咨询
关于Android API 31中
android:exported属性的配置疑问 迁移至API 31时,必须为应用组件指定android:exported="true"或android:exported="false",但官方给出的相关准则表述不够明确:
如果应用组件包含LAUNCHER类别,需将android:exported设为true。在大多数其他情况下,设为false。
一、处理android.intent.category.LAUNCHER的Activity
对于声明了android.intent.category.LAUNCHER的Activity,必须设置android:exported="true",示例配置如下:
<activity android:name=".MainActivity" android:label="@string/app_name" android:exported="true" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
二、处理自定义广播的Receiver
针对处理自定义Action的广播接收器,是否应该设置android:exported="false"?示例配置如下:
<receiver android:name="com.xxx.sticky.UnstickStickyBroadcastReceiver" android:exported="false" > <intent-filter> <action android:name="com.xxx.sticky.action.UNSTICK" /> </intent-filter> </receiver>
三、处理系统广播的Receiver
对于处理以下系统Action的广播接收器,应该设置android:exported="false"还是true?
android.appwidget.action.APPWIDGET_UPDATEandroid.appwidget.action.APPWIDGET_DELETEDandroid.intent.action.BOOT_COMPLETED
当前测试使用android:exported="false"是可行的,示例配置如下:
<receiver android:name="com.xxx.widget.MiniNoteAppWidgetProvider" android:label="@string/widget_mini_name" android:exported="false" > <intent-filter > <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> <action android:name="android.appwidget.action.APPWIDGET_DELETED" /> </intent-filter> <meta-data android:name="android.appwidget.provider" android:resource="@xml/mini_note_widget_info" /> </receiver> <receiver android:name="com.xxx.reminder.BootBroadcastReceiver" android:enabled="true" android:exported="false" > <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver>
疑问
是否有明确的官方准则可以指导这类android:exported属性的配置决策?
内容的提问来源于stack exchange,提问作者Cheok Yan Cheng
相关产品推荐
相关产品推荐

