I want to start an a third part activity when my Accessibility Service is connected. So I'm writing the below code in onServiceConnected()
method
@Override
public void onServiceConnected(ComponentName className,
IBinder service) {
Intent launchIntent = getPackageManager().getLaunchIntentForPackage(THIRD_PARTY_APP_PACKAGE);
if (launchIntent != null) {
getApplicationContext().startActivity(launchIntent);
}
}
The same code, when written inside onClick of a button in my application, works fine. I even debugged it to check whether the code is getting executed, and the line
getApplicationContext().startActivity(launchIntent);
executes without any exception but that app is not launched.
Also, when I try to open my own activity from the service like below, it doesn't work
Intent intent = new Intent(getApplicationContext(), FormActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(intent);
EDIT
I'm using Android 10
you can startActivity directly in AccessibilityService,don't need to getApplicationContext and startActivity.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.