when i run my code with compileSdkVersion 30 doesn't work but in 29 code working
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);
}
In api 30 bindService return false and serviceConnection doesn't respond to listeners
How to solve this problem ?
It might be related to the package visibility settings introduced in Android 11. When you have 2 apps: server with the service you are exposing and client that wants to bind that service - the client needs to declare in its Manifest that it can use the service package, like:
Otherwise binding will return false, and in system-wide Logcat you will see something like:
Because without this Manifest declaration the server app service is invisible for client app. Its still possible to start it from the
adb
if you want to check if the intent data is correct.More info: https://developer.android.com/training/package-visibility/declaring