Guest User

MyAccessibility.class

a guest
May 30th, 2020
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.11 KB | None | 0 0
  1. package com.apakula.bottonconrolbar;
  2.  
  3. import android.accessibilityservice.AccessibilityService;
  4. import android.content.Intent;
  5. import android.util.Log;
  6. import android.view.accessibility.AccessibilityEvent;
  7. import android.view.accessibility.AccessibilityNodeInfo;
  8. import android.widget.Toast;
  9.  
  10. public class MyService extends AccessibilityService {
  11.     private static final String TAG="BottomControlBarService";
  12.  
  13.     @Override
  14.     public void onAccessibilityEvent(AccessibilityEvent event) {
  15.         Log.i(TAG,"onAccessibilityEvent");
  16.  
  17.         AccessibilityNodeInfo source= event.getSource();
  18.         String viewIdName = source.getViewIdResourceName();
  19.         Log.d(TAG, (viewIdName != null) ? viewIdName : "NO VIEW ID");
  20.  
  21.         checkViewElementInfo(event);
  22.     }
  23.  
  24.     @Override
  25.     public void onInterrupt() {
  26.  
  27.     }
  28.  
  29.     @Override
  30.     protected void onServiceConnected() {
  31.         super.onServiceConnected();
  32.         Log.i(TAG,"onServiceConnected");
  33.         startApp();
  34.     }
  35.  
  36.     private void startApp() {
  37.         Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.amazon.mShop.android.shopping");
  38.         launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  39.         launchIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
  40.         if (launchIntent != null) {
  41.            getApplicationContext().startActivity(launchIntent);
  42.         } else {
  43.             Toast.makeText(getApplicationContext(), "There is no package available in android", Toast.LENGTH_LONG).show();
  44.         }
  45.     }
  46.  
  47.     private void checkViewElementInfo(AccessibilityEvent event) {
  48.         if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_CLICKED) {
  49.             AccessibilityNodeInfo nodeInfo = event.getSource();
  50.             if (nodeInfo == null) {
  51.                 return;
  52.             }
  53.             nodeInfo.refresh();
  54.             Log.d(TAG, "ClassName:" + nodeInfo.getClassName() +
  55.                     " Text:" + nodeInfo.getText() +
  56.                     " ViewIdResourceName:" + nodeInfo.getViewIdResourceName() +
  57.                     " isClickable:" + nodeInfo.isClickable());
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment