You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android无Root实现跨应用自动点击、后台模拟点击的方案咨询

Android无Root自动点击器实现方案

现有代码失效原因

你当前使用的Runtime.getRuntime().exec("input tap 950 581")方案存在两个核心限制:

  • 该命令本质是通过当前应用进程调用shell执行,应用退出后进程被回收,命令自然无法继续执行
  • 普通应用进程调用input系列命令默认无跨应用执行权限,仅能在本应用前台运行时生效,无法满足后台点击的需求

无Root实现的主流方案

Play商店同类应用普遍采用无障碍服务(AccessibilityService) 实现无Root点击,该方案支持Android 7.0(API 24)及以上系统,用户手动开启无障碍权限后,即使应用退到后台、主页面销毁也能正常执行点击操作。
除了无障碍服务方案外,还有一种ADB授权方案:给应用授予android.permission.WRITE_SECURE_SETTINGS权限后也可实现跨应用点击,但需要用户手动连接电脑执行ADB命令,操作门槛较高,普通应用很少采用。

核心实现步骤

  1. 在AndroidManifest.xml中注册无障碍服务,添加权限与配置:
<service
    android:name=".YourAccessibilityService"
    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/accessibility_service_config" />
</service>
  1. 在res/xml目录下创建accessibility_service_config.xml配置文件:
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
    android:accessibilityEventTypes="typeAllMask"
    android:accessibilityFeedbackType="feedbackGeneric"
    android:accessibilityFlags="flagDefault|flagEnableAccessibilityVolume|flagIncludeNotImportantViews|flagRequestTouchExplorationMode"
    android:canPerformGestures="true"
    android:description="@string/accessibility_service_desc" />

注意android:canPerformGestures="true"必须配置,才能获取手势执行权限。
3. 继承AccessibilityService实现点击逻辑,核心调用dispatchGesture方法执行点击:

// 执行坐标(x,y)的点击操作
private void performClick(float x, float y) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
        return;
    }
    Path clickPath = new Path();
    clickPath.moveTo(x, y);
    GestureDescription.StrokeDescription clickStroke =
            new GestureDescription.StrokeDescription(clickPath, 0, 100);
    GestureDescription.Builder builder = new GestureDescription.Builder();
    builder.addStroke(clickStroke);
    dispatchGesture(builder.build(), null, null);
}

注意事项

  • 无障碍权限无法静默申请,需要引导用户手动前往系统「无障碍」设置页面为你的应用开启
  • 若需要长期后台运行不被系统回收,可给服务绑定前台通知,提升进程优先级
  • 适配Android 12及以上版本时,注意添加对应的权限声明,避免权限被拦截

内容的提问来源于stack exchange,提问作者Arthur Rodrigues

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.04 06:57:03