gpt4 book ai didi

android - 在 Android 11 上,从客户端应用程序调用远程绑定(bind)服务绑定(bind)失败

转载 作者:行者123 更新时间:2023-12-05 00:10:27 25 4
gpt4 key购买 nike

安卓 11 从客户端应用程序调用远程绑定(bind)服务绑定(bind)失败
问题仅针对 Android 11。
1:使用带有 AIDL 接口(interface)的远程绑定(bind)服务。该服务是从服务 B 派生的,该服务也使用 AIDL 接口(interface)。

public class IPCEnterpriseServicePcsc extends IPCServicePcsc {
...
protected IPCEnterpriseInterfaceLicense licenseBinder;
...
}

public class IPCEnterpriseInterfaceLicense extends IRemotePcscServiceLicense.Stub {...}

public class IPCServicePcsc extends IPCService {
...
protected IPCInterfacePcsc mBinder;
...
}

public class IPCInterfacePcsc extends IRemotePcscService.Stub{...}
2. 以下是定义服务的服务器应用程序 list :
    <service android:label="@string/pcsc_service_name" android:name=".IPCEnterpriseServicePcsc" >
<intent-filter>
<action android:name="com.baimobile.android.enterprise.credential.service.ipc.action.BIND_PCSC" />
<action android:name="com.baimobile.android.enterprise.credential.service.ipc.action.BIND_LICENSE" />
<action android:name="com.baimobile.android.enterprise.credential.service.license.action.VALIDATE_USER_LICENSE_INFO" />
</intent-filter>
</service>

server app id is "com.baimobile.android.enterprise.credential.service"
3.1 从客户端应用程序调用服务“IPCEnterpriseServicePcsc”,如下所示:
Intent intent = new Intent("com.baimobile.android.enterprise.credential.service.ipc.action.BIND_LICENSE");
intent.setPackage("com.baimobile.android.enterprise.credential.service");
intent.putExtra("接口(interface)","IRemotePcscServiceLicense");
boolean pcscServiceInstalled = appContext.bindService(intent, connectionToPcscInterface, Context.BIND_AUTO_CREATE);
3.2: connectionToPcscInterface 定义为:
private ServiceConnection connectionToPcscInterface = new ServiceConnection() {
public void onServiceConnected(ComponentName remoteComponent, IBinder binder) {...};
public void onServiceDisconnected(ComponentName arg0) {..};
}
3.3:在步骤 3.1 中成功的 appContext.bindService() 后,在步骤 3.2 中提到的 onServiceConnected() 被服务调用。这里我们做一些验证,然后绑定(bind)到基类服务 IPCServicePcsc
    Intent intent = new Intent("com.baimobile.android.pcsclite.service.ipc.action.BIND_PCSC");
intent.setPackage("com.baimobile.android.enterprise.credential.service");
intent.putExtra("Interface","IRemotePcscService"); // Request the PC/SC interface instead of the license interface.
pcscServiceInstalled = appContext.bindService(intent, connectionToPcscInterface, Context.BIND_AUTO_CREATE);
if( ! pcscServiceInstalled ){
Log.e("TAG","bindService failed.");
}
问题陈述:
在 Android 10 之前,客户端应用程序能够很好地与这些服务连接,但是在 Android 11 上,步骤 3.3 下的绑定(bind)失败。
知道可能是什么问题,并寻找解决问题的建议。似乎在 Android 11 上有些损坏或硬化。

最佳答案

如果您还没有这样做,您的客户端应用程序需要 a <queries> element in the manifest识别服务应用程序。
例如,在 this client app , 我有:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.commonsware.android.r.embed.client">
<queries>
<package android:name="com.commonsware.android.r.embed.server" />
</queries>

<application
android:name=".MainApp"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
<queries>元素标识 a separate app的包具有客户端应用程序绑定(bind)到的绑定(bind)服务。

关于android - 在 Android 11 上,从客户端应用程序调用远程绑定(bind)服务绑定(bind)失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66691117/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com