Skip to content
Ven edited this page Aug 13, 2023 · 18 revisions

1. 添加依赖

1.1 将JitPack仓库添加到根目录build.gradle文件中

allprojects {
    repositories {
    	//添加JitPack仓库
        maven { url 'https://jitpack.io' }
    }
}

1.2 添加依赖到主模块的build.gradle中,

dependencies {
	//添加依赖
    implementation 'com.github.ven-coder:assists:1.0.1'
}

2. 注册服务

主模块AndroidManifest.xml中注册服务

一定要在主模块中注册服务,不然进程被杀服务也会自动被关闭需要再次开启

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.ven.assists.simple">

    <application
        android:name="com.ven.assists.simple.App"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:requestLegacyExternalStorage="true"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        android:usesCleartextTraffic="true">
        <!-- 添加以下代码 -->
        <service
            android:name="com.ven.assist.AssistsService"
            android:enabled="true"
            android:exported="true"
            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/assists_service" />
        </service>
    </application>

</manifest>

3. 实现业务逻辑

3.1 继承StepImpl

实现onImpl(collector: StepCollector)接口,通过collector.next()实现步骤逻辑

class OpenWechat:StepImpl {
    override fun onImpl(collector: StepCollector) {
        collector.next(1) {
        	//步骤1逻辑
        	//打开微信
            Intent().apply {
                addCategory(Intent.CATEGORY_LAUNCHER)
                addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                component = ComponentName("com.tencent.mm", "com.tencent.mm.ui.LauncherUI")
                Assists.service?.startActivity(this)
            }
            //步骤1执行完,紧接执行步骤2
            StepManager.execute(this::class.java, 2)
        }.next(2) {
        	//步骤2逻辑
        	//查找通讯录按钮
        	UIOperate.findByText("通讯录").forEach {
                //获取到按钮后执行其他逻辑
            }
        }
    }
}

3.2 在执行前注册上面步骤实现类OpenWechat

StepManager.register(OpenWechat::class.java)

4. 执行

执行前请确保无障碍服务已开启,开始执行请使用beginExecute(),后续的步骤执行请使用execute()方法

//从步骤1开始执行
StepManager.beginExecute(OpenWechat::class.java, 1)

示例&下载

▶示例视频

📥直接下载或扫码下载

Clone this wiki locally