Getting Layout name of the Activity using Accessibility Service in Android -


i trying create app package name, activity name , activity layout name (xml)of other apps. purpose using accessibility service window_state_changed of foreground window.

what have achieved?

i able package name , activity name of other apps using accessibility service.

what not able achieve!

i have tried possible solutions layout name of activity, unfortunately failing each , every successive attempts.

what have tried far:

step 1:

created accessibilityservice.xml under res/xml folder below

<accessibility-service     xmlns:tools="http://schemas.android.com/tools"     android:accessibilityeventtypes="typewindowstatechanged"     android:accessibilityfeedbacktype="feedbackgeneric"     android:accessibilityflags="flagincludenotimportantviews"     android:canretrievewindowcontent="true"     xmlns:android="http://schemas.android.com/apk/res/android"     tools:ignore="unusedattribute"/> 

step 2:

created windowchangedetectingservice.java service class , logged package name , activity below

    import android.accessibilityservice.accessibilityservice;     import android.accessibilityservice.accessibilityserviceinfo;     import android.app.activity;     import android.content.componentname;     import android.content.pm.activityinfo;     import android.content.pm.packagemanager;     import android.os.build;     import android.util.log;     import android.view.view;     import android.view.viewgroup;     import android.view.accessibility.accessibilityevent;     import android.view.accessibility.accessibilitynodeinfo;      import java.util.list;      public class windowchangedetectingservice extends accessibilityservice {          @override         protected void onserviceconnected() {             super.onserviceconnected();              //configure these here compatibility api 13 , below.             accessibilityserviceinfo config = new accessibilityserviceinfo();             config.eventtypes = accessibilityevent.type_window_state_changed;             config.feedbacktype = accessibilityserviceinfo.feedback_generic;              if (build.version.sdk_int >= 16)                 //just in case helps                 config.flags = accessibilityserviceinfo.flag_include_not_important_views;              setserviceinfo(config);         }          @override         public void onaccessibilityevent(accessibilityevent event) {              if (event.geteventtype() == accessibilityevent.type_window_state_changed) {                 if (event.getpackagename() != null && event.getclassname() != null) {                     componentname componentname = new componentname(                         event.getpackagename().tostring(),                         event.getclassname().tostring()                      );                       log.i("accesspackagename",  event.getpackagename().tostring());                     log.i("accessgetclassname",  event.getclassname().tostring());                  }             }         } } 

step 3: registered windowchangedetectingservice created in manifest.xml below

<service             android:name=".windowchangedetectingservice"             android:permission="android.permission.bind_accessibility_service">             <intent-filter>                 <action android:name="android.accessibilityservice.accessibilityservice"/>             </intent-filter>             <meta-data                 android:name="android.accessibilityservice"                 android:resource="@xml/accessibilityservice"/>         </service> 

output: (retrieved logcat)

08-18 12:51:45.430 11206-11206/com.takeoffandroid.screenlog i/accesspackagename: com.takeoffandroid.screenlog 08-18 12:51:45.430 11206-11206/com.takeoffandroid.screenlog i/accessgetclassname: com.takeoffandroid.screenlog.mainactivity 

my requirement: (expected output)

08-18 12:51:45.430 11206-11206/com.takeoffandroid.screenlog i/accesspackagename: com.takeoffandroid.screenlog     08-18 12:51:45.430 11206-11206/com.takeoffandroid.screenlog i/accessgetclassname: com.takeoffandroid.screenlog.mainactivity  --------------------------------------------------------------------    --------------------------------------------------------------------      08-18 12:51:45.430 11206-11206/com.takeoffandroid.screenlog i/accessgetlayoutname: activity_main.xml //should capable read layout name of mainactivity  --------------------------------------------------------------------   -------------------------------------------------------------------- 

i have been working on requirement since past 2 days not able find method or ways in android using accessibility service. or suggestions helpful me. in advance.

you need modify service config include view id names in accessibility node infos.

<accessibility-service xmlns:tools="http://schemas.android.com/tools" android:accessibilityeventtypes="typewindowstatechanged" android:accessibilityfeedbacktype="feedbackgeneric" android:accessibilityflags="flagreportviewids|flagincludenotimportantviews" android:canretrievewindowcontent="true" xmlns:android="http://schemas.android.com/apk/res/android" tools:ignore="unusedattribute"/> 

the important change here this:

android:accessibilityflags="flagreportviewids|flagincludenotimportantviews"

or more portion:

flagreportviewids

also, should not include onserviceconnected function. you're modifying of configuration you're doing in service_config xml file. you're not quite doing correctly. creating new service info dangerous, you're unlikely populate of fields matter. line:

accessibilityserviceinfo config = new accessibilityserviceinfo(); 

should this:

accessibilityserviceinfo config = getserviceinfo() 

and modify that! although, seriously, don't this, rely on service_config xml props.

once have proper configuration, should able this:

someaccessibilitynodeinfo.getviewidresourcename() 

which id looking for.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -