-1

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

Vishal Afre
  • 1,013
  • 3
  • 12
  • 39

1 Answers1

0

you can startActivity directly in AccessibilityService,don't need to getApplicationContext and startActivity.

Neo Chen
  • 41
  • 3