在android 11以下版本手机上绑定的好好的,怎么在android 11以上设备就不行了呢?
android 11新增的特性中有个“管理软件包可见性”
看到这里小伙伴们是不是反应过来恍然大悟了,就是这个鬼东西导致呀。
服务端我们的包名是“com.example.aidlserver”
<service
android:name=".MyAidlService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.example.aidlserver" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</service>
客户端
Intent intent = new Intent();
intent.setAction("com.example.aidlserver");
intent.setPackage("com.example.aidlserver");
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
val intent = Intent()
intent.setAction("com.example.aidlserver")
intent.setPackage("com.example.aidlserver")
bindService(intent, mConnection, Context.BIND_AUTO_CREATE)
为了客户端能访问到服务端app我们要添加下面配置
<queries>
<package android:name="com.example.aidlserver" />
<intent>
<action android:name="com.example.aidlserver" />
</intent>
</queries>
到这里是不是完了呢,别急这个只解决了客服端访问问题,服务端还有问题
此时仍需把服务端app设置为自启动,部分平板中的位置是设置->系统->自动运行
下面是小米设备上的示例:


“允许被其他应用唤醒”打开这样就能被aidl的客户端唤起了,到这里aidl 客户端就能正常访问服务端了。