use of com.stardust.autojs.annotation.ScriptInterface in project Auto.js by hyb1996.
the class AppUtils method getPackageName.
@ScriptInterface
public String getPackageName(String appName) {
PackageManager packageManager = mContext.getPackageManager();
List<ApplicationInfo> installedApplications = packageManager.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo applicationInfo : installedApplications) {
if (packageManager.getApplicationLabel(applicationInfo).toString().equals(appName)) {
return applicationInfo.packageName;
}
}
return null;
}
use of com.stardust.autojs.annotation.ScriptInterface in project Auto.js by hyb1996.
the class AppUtils method launchPackage.
@ScriptInterface
public boolean launchPackage(String packageName) {
try {
PackageManager packageManager = mContext.getPackageManager();
mContext.startActivity(packageManager.getLaunchIntentForPackage(packageName).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
return true;
} catch (Exception e) {
return false;
}
}
use of com.stardust.autojs.annotation.ScriptInterface in project Auto.js by hyb1996.
the class UiSelector method findOne.
@ScriptInterface
public UiObject findOne(long timeout) {
if (timeout == -1) {
return untilFindOne();
}
UiObjectCollection uiObjectCollection = find();
long start = SystemClock.uptimeMillis();
while (uiObjectCollection.empty()) {
if (Thread.currentThread().isInterrupted()) {
throw new ScriptInterruptedException();
}
if (SystemClock.uptimeMillis() - start > timeout) {
return null;
}
try {
Thread.sleep(50);
} catch (InterruptedException e) {
throw new ScriptInterruptedException();
}
uiObjectCollection = find();
}
return uiObjectCollection.get(0);
}
use of com.stardust.autojs.annotation.ScriptInterface in project Auto.js by hyb1996.
the class UiSelector method find.
@NonNull
@ScriptInterface
public UiObjectCollection find() {
ensureAccessibilityServiceEnabled();
AccessibilityNodeInfo root = mAccessibilityBridge.getRootInActiveWindow();
if (root == null) {
return UiObjectCollection.EMPTY;
}
if (root.getPackageName() != null && mAccessibilityBridge.getConfig().whiteListContains(root.getPackageName().toString())) {
Log.d(TAG, "package in white list, return null");
return UiObjectCollection.EMPTY;
}
return findOf(UiObject.createRoot(root, mAllocator));
}
use of com.stardust.autojs.annotation.ScriptInterface in project Auto.js by hyb1996.
the class AppUtils method getAppName.
@ScriptInterface
public String getAppName(String packageName) {
PackageManager packageManager = mContext.getPackageManager();
try {
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(packageName, 0);
CharSequence appName = packageManager.getApplicationLabel(applicationInfo);
return appName == null ? null : appName.toString();
} catch (PackageManager.NameNotFoundException e) {
return null;
}
}
Aggregations