fix rn-auto
This commit is contained in:
@@ -2,6 +2,7 @@ package com.rnbot;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.provider.Settings;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
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) {
|
||||
WritableMap map = new WritableNativeMap();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user