下午好🌅🌅🌅
本答案参考通义千问
你遇到的问题是因为从 Android 12 开始,如果你的应用目标 SDK 版本是 Android 12 或更高版本,并且你的 <activity> 元素中定义了 <intent-filter>,那么你必须显式地设置 android:exported 属性。
根据你的描述,你已经为 <activity> 设置了 android:exported="true",但仍然出现了错误。这可能是因为某些地方没有正确设置或者有其他未被注意到的 <activity> 元素。
以下是详细的解决方案:
-
检查所有 <activity> 元素:确保每个带有 <intent-filter> 的 <activity> 都明确设置了 android:exported 属性。
-
添加或更新 android:exported 属性:确保所有 <activity> 元素都包含 android:exported 属性。
下面是修改后的 AndroidManifest.xml 示例:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.o3dr.android.client">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<!-- Support devices without Bluetooth since there are other connection types -->
<uses-feature
android:name="android.hardware.bluetooth"
android:required="false"/>
<!-- Support devices without USB host mode since there are other connection types -->
<uses-feature
android:name="android.hardware.usb.host"
android:required="false"/>
<!-- Support devices that don't have location services -->
<uses-feature
android:name="android.hardware.location.gps"
android:required="false"/>
<uses-feature
android:name="android.hardware.location.network"
android:required="false"/>
<uses-feature
android:name="android.hardware.location"
android:required="false"/>
<application>
<activity
android:name="org.droidplanner.services.android.impl.ui.activity.UsbIntentReceiver"
android:launchMode="singleInstance"
android:noHistory="true"
android:exported="true"
android:excludeFromRecents="true">
<!-- USB connection intent -->
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"/>
</intent-filter>
<meta-data
android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="@xml/device_filter"/>
</activity>
<service
android:name="org.droidplanner.services.android.impl.api.DroidPlannerService"
android:exported="true"
android:enabled="false">
<!-- Filter and meta data for the Tower lib runtime -->
<intent-filter>
<action android:name="com.o3dr.services.android.lib.model.IDroidPlannerServices" />
</intent-filter>
<meta-data
android:name="com.o3dr.dronekit.android.core.version"
android:value="@integer/core_lib_version" />
</service>
</application>
</manifest>
关键点:
- 确保所有带有
<intent-filter> 的 <activity> 元素都有 android:exported 属性。 - 在示例中,
android:exported="true" 已经被设置在 <activity> 元素中。
通过以上步骤,你应该能够解决 android:exported 需要显式指定的问题。