Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/195.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在api 30中返回假BindService_Android_Android Intent_Serviceconnection_Bindservice - Fatal编程技术网

Android 在api 30中返回假BindService

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

当我用编译器运行我的代码时,DK30版本不起作用,但在29代码中起作用

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及以下版本上,没有任何问题