问题
I'm working in Accessibility Service. i need to get the app name using Accessibility Service. i have studied the documentation of the Accessibility Service in developer's of Android website. but there is no mention about getting the app name using Accessibility.
Is this possible to get the name of the application? i think its possible because talk back getting name of the application. So if there is any way to get name of the application, Please give your suggestion.
回答1:
You can't get the "app name" of the application. At least not reliably. The strings that the app reads out are things like the title of the Title Bar, or the string underneath the apps icon. It never actually directly asks the framework for the title of the app it is attached to.
You do, however, have access to the application package.
someAccessibilityNodeInfo.getPackageName();
This uniquely identifies the application that a given AccessibilityNodeInfo was sent from.
You could also consider using this:
someAccessibilityService.getRootInActiveWindow();
And crawl down the view hierarchy looking for a title bar.
来源:https://stackoverflow.com/questions/31112965/get-the-name-of-the-app-using-accessibility-service-in-android