同套项目拥有两款设备,一款Android10绑定正常,另一款Android11绑定失败,便开始研究原因。
先晒一下新版本特性管理软件包可见性。
直接谈解决方案。
在确保服务端的AndroidManifest.xml配置和客户端的package以及action对应的情况下。
服务端 假设服务端的包名为"com.aidl.demo"
<service android:name=".AidlService"
android:enabled="true"
android:exported="true"
android:process=":remote">
<intent-filter >
<action android:name="AIDL.service"></action>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</service>
客户端
val intent = Intent()
intent.setAction("AIDL.service")
intent.setPackage("com.aidl.demo")
bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE)
此时在Android11中的客户端中的AndroidManifest.xml还需另外配置。
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"
tools:ignore="QueryAllPackagesPermission" />
<queries>
<package android:name="com.aidl.demo" />
<intent>
<action android:name="AIDL.service" />
</intent>
</queries>
之后发现仍然有问题。
此时需要在设置中将服务端应用设置为自启动。
部分平板中的位置为 设置 - 系统 - 自动运行。
其他设备直接进入应用信息设置权限即可。
设置完成以上操作后,服务正常连接,搞定。