Java Code Examples for android.accessibilityservice.AccessibilityService#performGlobalAction()

The following examples show how to use android.accessibilityservice.AccessibilityService#performGlobalAction() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AccessUtil.java    From pc-android-controller-android with Apache License 2.0 6 votes vote down vote up
/**
 * 返回事件
 */
public static void performBack(final AccessibilityService service, AccessibilityNodeInfo nodeInfo) {
    CharSequence packageName = nodeInfo.getPackageName();
    if (!(packageName+"").equals(WECHAT_PACKAGE_NAME)) {
        L.d("不是微信,不能后退 " + packageName);
        return;
    }
    if (service == null) {
        L.e("performBackWithDelay service is null");
        return;
    }
    if (service.getRootInActiveWindow() == null) {
        L.e("performBackWithDelay rootNode is null");
        return;
    }
    L.d("performBack Reboot ");
    service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK);
}
 
Example 2
Source File: AccessibilityUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 模拟全局对应 Action 操作
 * @param service {@link AccessibilityService}
 * @param action  操作意图
 * @return {@code true} success, {@code false} fail
 */
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
public static boolean performGlobalAction(final AccessibilityService service, final int action) {
    if (service != null) {
        return service.performGlobalAction(action);
    }
    return false;
}
 
Example 3
Source File: Util.java    From Float-Bar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 模拟最近任务
 * 
 * @param service
 */
public static void recentApps(AccessibilityService service) {
	if (VERSION.SDK_INT < 16) {
		Toast.makeText(service, "Android 4.1及以上系统才支持此功能,请升级后重试", 1).show();
	} else {
		service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_RECENTS);
	}
}
 
Example 4
Source File: Util.java    From Float-Bar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 模拟返回键 API 16(Android 4.1)及以上才能用
 * 
 * @param service
 */
public static void virtualBack(AccessibilityService service) {
	if (VERSION.SDK_INT < 16) {
		Toast.makeText(service, "Android 4.1及以上系统才支持此功能,请升级后重试", 1).show();
	} else {
		service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK);
	}
}
 
Example 5
Source File: Util.java    From Float-Bar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 模拟最近任务
 * 
 * @param service
 */
public static void recentApps(AccessibilityService service) {
	if (VERSION.SDK_INT < 16) {
		Toast.makeText(service, "Android 4.1及以上系统才支持此功能,请升级后重试", 1).show();
	} else {
		service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_RECENTS);
	}
}
 
Example 6
Source File: Util.java    From Float-Bar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 模拟返回键 API 16(Android 4.1)及以上才能用
 * 
 * @param service
 */
public static void virtualBack(AccessibilityService service) {
	if (VERSION.SDK_INT < 16) {
		Toast.makeText(service, "Android 4.1及以上系统才支持此功能,请升级后重试", 1).show();
	} else {
		service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK);
	}
}
 
Example 7
Source File: AccessUtil.java    From pc-android-controller-android with Apache License 2.0 5 votes vote down vote up
/**
 * 返回事件
 */
public static void performHome(final AccessibilityService service) {
    if (service == null) {
        L.e("performBackWithDelay service is null");
        return;
    }
    if (service.getRootInActiveWindow() == null) {
        L.e("performBackWithDelay rootNode is null");
        return;
    }
    L.d("performHome");
    service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_HOME);
}
 
Example 8
Source File: FloatingBallUtils.java    From RelaxFinger with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 使用原生home键返回桌面,存在5秒延迟问题
 * @param service
 */
public static void keyHome(AccessibilityService service){

    service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_HOME);
}
 
Example 9
Source File: FloatingBallUtils.java    From RelaxFinger with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 快速设置
 * @param service
 */
public static void openQuickSetting(AccessibilityService service){

    service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_QUICK_SETTINGS);
}
 
Example 10
Source File: GlobalMenuItem.java    From talkback with Apache License 2.0 4 votes vote down vote up
/**
 * @param iconResource Resource id for the icon that represents this action
 * @param text Human readable description of this action
 * @param service The accessibility service that will be used to perform the given global action
 * @param action The global action that corresponds to this menu item
 */
private GlobalMenuItem(
    int iconResource,
    String text,
    final AccessibilityService service,
    final int action,
    @Nullable final SelectMenuItemListener selectMenuItemListener) {
  onClickListener =
      new MenuItemOnClickListener() {

        @Override
        public void onClick() {
          service.performGlobalAction(action);

          if (selectMenuItemListener != null) {
            switch (action) {
              case AccessibilityService.GLOBAL_ACTION_BACK:
                selectMenuItemListener.onMenuItemSelected(
                    SwitchAccessMenuItemEnum.MenuItem.GLOBAL_MENU_BACK);
                break;
              case AccessibilityService.GLOBAL_ACTION_HOME:
                selectMenuItemListener.onMenuItemSelected(
                    SwitchAccessMenuItemEnum.MenuItem.GLOBAL_MENU_HOME);
                break;
              case AccessibilityService.GLOBAL_ACTION_RECENTS:
                selectMenuItemListener.onMenuItemSelected(
                    SwitchAccessMenuItemEnum.MenuItem.GLOBAL_MENU_RECENTS);
                break;
              case AccessibilityService.GLOBAL_ACTION_NOTIFICATIONS:
                selectMenuItemListener.onMenuItemSelected(
                    SwitchAccessMenuItemEnum.MenuItem.GLOBAL_MENU_NOTIFICATIONS);
                break;
              case AccessibilityService.GLOBAL_ACTION_QUICK_SETTINGS:
                selectMenuItemListener.onMenuItemSelected(
                    SwitchAccessMenuItemEnum.MenuItem.GLOBAL_MENU_QUICK_SETTINGS);
                break;
              case AccessibilityService.GLOBAL_ACTION_POWER_DIALOG:
                selectMenuItemListener.onMenuItemSelected(
                    SwitchAccessMenuItemEnum.MenuItem.GLOBAL_MENU_POWER_DIALOG);
                break;
              default:
                // This should never happen.
                // TODO: Use
                // com.google.android.libraries.accessibility.utils.log.LogUtils
                // because it has more convenience methods
                LogUtils.e(TAG, "Invalid global action: %d", action);
            }
          }
        }
      };
  this.service = service;
  this.iconResource = iconResource;
  this.text = text;
}
 
Example 11
Source File: AccessibilityHelper.java    From WechatHook-Dusan with Apache License 2.0 4 votes vote down vote up
public static void performBack(AccessibilityService service) {
    if(service == null) {
        return;
    }
    service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK);
}
 
Example 12
Source File: AccessibilityHelper.java    From WechatHook-Dusan with Apache License 2.0 4 votes vote down vote up
public static void performHome(AccessibilityService service) {
    if(service == null) {
        return;
    }
    service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_HOME);
}
 
Example 13
Source File: OperationExecutor.java    From SoloPi with Apache License 2.0 4 votes vote down vote up
/**
 * 执行设备控制动作
 *
 * @param method
 */
private boolean executeDeviceAction(OperationMethod method, final OperationContext opContext) {
    AccessibilityService service = serviceRef.get();
    PerformActionEnum actionEnum = method.getActionEnum();

    switch (actionEnum) {
        case HOME:
            if (service != null) {
                service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_HOME);
            } else {
                executor.executeCmd("input keyevent 3");
            }
            break;
        case NOTIFICATION:
            if (service != null) {
                service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_NOTIFICATIONS);
            } else {
                executor.executeCmd("input keyevent 83");
            }
            break;
        case RECENT_TASK:
            if (service != null) {
                service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_RECENTS);
            }
            break;
        case DEVICE_INFO:
            UIOperationMessage message = new UIOperationMessage();
            message.eventType = UIOperationMessage.TYPE_DEVICE_INFO;
            injectorService.pushMessage(null, message, false);
            break;
        case SCREENSHOT:
            String screenShot = method.getParam(INPUT_TEXT_KEY);
            if (StringUtil.isEmpty(screenShot)) {
                return false;
            }
            final String screenshotName = screenShot + ".png";
            opContext.notifyOnFinish(new Runnable() {
                @Override
                public void run() {
                    File parentDir = FileUtils.getSubDir("screenshots");
                    boolean result = true;
                    if (!parentDir.exists()) {
                        result = parentDir.mkdirs();
                    }

                    if (result) {
                        File screenshot = new File(parentDir, screenshotName);
                        // 如果可以,通过minicap截图
                        if (captureService != null) {
                            Bitmap bit = captureService.captureScreen(screenshot, opContext.screenWidth,
                                    opContext.screenHeight, opContext.screenWidth, opContext.screenHeight);
                            if (bit != null) {
                                return;
                            }
                        }

                        String path = FileUtils.getPathInShell(screenshot);
                        CmdTools.execAdbCmd("screencap -p \"" + path + "\"", 0);
                    }
                }
            });
            return true;
    }

    opContext.notifyOperationFinish();
    operationManagerRef.get().invalidRoot();
    return true;
}
 
Example 14
Source File: FloatingBallUtils.java    From RelaxFinger with GNU General Public License v2.0 2 votes vote down vote up
public static void keyBack(AccessibilityService service){

        service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK);
    }
 
Example 15
Source File: FloatingBallUtils.java    From RelaxFinger with GNU General Public License v2.0 2 votes vote down vote up
public static void openRecnetTask(AccessibilityService service){

        service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_RECENTS);


    }
 
Example 16
Source File: FloatingBallUtils.java    From RelaxFinger with GNU General Public License v2.0 2 votes vote down vote up
public static void openNotificationBar(AccessibilityService service){
    service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_NOTIFICATIONS);

}
 
Example 17
Source File: FloatingBallUtils.java    From RelaxFinger with GNU General Public License v2.0 2 votes vote down vote up
/**
 * 长按电源键
 */

public static void openPowerDialog(AccessibilityService service){

    service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_POWER_DIALOG);
}
 
Example 18
Source File: FloatingBallUtils.java    From RelaxFinger with GNU General Public License v2.0 2 votes vote down vote up
public static void previousApp(AccessibilityService service){

        service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_RECENTS);
        service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_RECENTS);

    }