Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is getClassName() enough to identify an activity in android?

If I’m using an accessibility service to get the activity that user currently has opened anywhere on their device, is event.getClassName() enough to distinguish this activity from any other activity on the device?

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {

    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
        Log.i(TAG, event.getClassName());
    }
}

So is it enough or is it possible that getClassName() might be the same for another activity? Meaning do I have to include event.getPackageName() as well to ensure the activity name is unique?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

is it possible that getClassName() might be the same for another activity?

Yes. This is especially true for apps that use third-party libraries that supply activities.

do I have to include event.getPackageName() as well to ensure the activity name is unique?

Yes. This is why ComponentName needs both the application ID and the class name.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading