Android 在api 30中返回假BindService
当我用编译器运行我的代码时,DK30版本不起作用,但在29代码中起作用Android 在api 30中返回假BindService,android,android-intent,serviceconnection,bindservice,Android,Android Intent,Serviceconnection,Bindservice,当我用编译器运行我的代码时,DK30版本不起作用,但在29代码中起作用 Intent intent = new Intent(); intent.setPackage("com.androidlearn.securityman"); ServiceConnection serviceConnection = new ServiceConnection() { @Override public void onServiceConnected(Component
Intent intent = new Intent();
intent.setPackage("com.androidlearn.securityman");
ServiceConnection serviceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
Log.e("","");
Toast.makeText(context,"onServiceConnected",Toast.LENGTH_LONG).show();
listener.onSuccess(IPaymentInterface.Stub.asInterface(service));
}
@Override
public void onServiceDisconnected(ComponentName name) {
Toast.makeText(context,"onServiceDisconnected",Toast.LENGTH_LONG).show();
Log.e("","");
listener.onFailure("connection failed");
}
};
context.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
}
在api 30中,bindService返回false,serviceConnection不响应侦听器
如何解决这个问题?关于如何在Android 11上使用前台服务,存在一些差异…您可以从那里开始。我只是使用binder ipc,而不是前台服务。当您调用“bindService”时,它的“上下文”有效且有效?如果尝试从已停止/已完成的活动绑定到服务,它将返回FALSE。是,活动正在运行。问题只出现在api 30及以下版本上,没有任何问题