fix rn-auto
This commit is contained in:
@@ -2,6 +2,7 @@ package com.rnbot;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.view.accessibility.AccessibilityNodeInfo;
|
import android.view.accessibility.AccessibilityNodeInfo;
|
||||||
import android.accessibilityservice.AccessibilityService;
|
import android.accessibilityservice.AccessibilityService;
|
||||||
@@ -149,6 +150,40 @@ public class RNBotModule extends ReactContextBaseJavaModule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ReactMethod
|
||||||
|
public void openApp(String packageName, String activityName, Promise promise) {
|
||||||
|
try {
|
||||||
|
Activity activity = getCurrentActivity();
|
||||||
|
if (activity == null) {
|
||||||
|
promise.reject("NO_ACTIVITY", "Activity is null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PackageManager pm = activity.getPackageManager();
|
||||||
|
Intent intent;
|
||||||
|
|
||||||
|
if (activityName != null && !activityName.isEmpty()) {
|
||||||
|
// 指定 Activity
|
||||||
|
intent = new Intent();
|
||||||
|
intent.setClassName(packageName, activityName);
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
|
} else {
|
||||||
|
// 只指定包名,启动主 Activity
|
||||||
|
intent = pm.getLaunchIntentForPackage(packageName);
|
||||||
|
if (intent == null) {
|
||||||
|
promise.reject("APP_NOT_FOUND", "应用未安装: " + packageName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
|
}
|
||||||
|
|
||||||
|
activity.startActivity(intent);
|
||||||
|
promise.resolve(true);
|
||||||
|
} catch (Exception e) {
|
||||||
|
promise.reject("ERROR", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private WritableMap nodeToMap(AccessibilityNodeInfo node) {
|
private WritableMap nodeToMap(AccessibilityNodeInfo node) {
|
||||||
WritableMap map = new WritableNativeMap();
|
WritableMap map = new WritableNativeMap();
|
||||||
|
|
||||||
|
|||||||
@@ -107,6 +107,12 @@ class RNAuto {
|
|||||||
return await RNBotModule.recents();
|
return await RNBotModule.recents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 打开应用 */
|
||||||
|
async openApp(packageName: string, activityName?: string): Promise<boolean> {
|
||||||
|
if (!this.checkAndroid()) return false;
|
||||||
|
return await RNBotModule.openApp(packageName, activityName || '');
|
||||||
|
}
|
||||||
|
|
||||||
/** 延迟 */
|
/** 延迟 */
|
||||||
delay(ms: number): Promise<void> {
|
delay(ms: number): Promise<void> {
|
||||||
return new Promise(resolve => setTimeout(resolve, ms));
|
return new Promise(resolve => setTimeout(resolve, ms));
|
||||||
|
|||||||
Reference in New Issue
Block a user