怎么检查是否存在应用分身?
我发现,app对象有很多好用的方法和函数。 app.launch() app.launchApp() app.launchPackage() app.launchSettings() app.openAppSetting() app.uninstall() app.kill()
分身: app.launchDual() app.launchDualPackage() app.launchDualApp() app.launchDualSettings() app.openDualAppSetting() app.uninstallDual() app.killDual()
安装有:app.isInstalled() 但是没有找到检查是否存在分身。
如果使用app.launchDual()虽然会返回false,如果存在的话,会打开分身app,多了其它步骤。
我的需求是提前检查是否存在分身,如果不存在,则不执行某些步骤。类似app.isInstalled()
怎么判断是否安装了分身?
感谢反馈.
目前 AutoJs6 还没有与 app.isInstalled 等价的 "分身是否已安装" 的检测 API (例如 app.isDualInstalled).
在正式提供 API 之前, 可以用下面的临时方案进行 "无启动" 的判断:
function detectDualUserId() {
const cmd = 'cmd user list';
let r;
if (autojs.isRootAvailable()) {
r = shell(cmd, {root: true});
} else if (shizuku.isOperational()) {
r = shizuku(cmd);
} else {
r = null;
}
let out = r ? r.result : '';
const candidates = [];
out.split('\n').forEach(line => {
const m = line.match(/UserInfo\{(\d+):([^\}:]+).*?\}/i);
if (m) {
const id = parseInt(m[1], 10);
const tag = m[2].toLowerCase();
if (tag.includes('xspace') || tag.includes('clone') || tag.includes('dual')) {
candidates.push(id);
}
}
});
if (candidates.length > 0) return candidates[0];
const ids = [];
out.split('\n').forEach(line => {
const m = line.match(/UserInfo\{(\d+):/);
if (m) ids.push(parseInt(m[1], 10));
});
const currentId = 0;
const others = ids.filter(x => x !== currentId);
if (others.length > 0) return Math.min.apply(null, others);
return 999;
}
function isDualInstalled(packageName) {
const userId = detectDualUserId();
const cmd = `cmd package list packages --user ${userId} ${packageName}`;
let r;
if (autojs.isRootAvailable()) {
r = shell(cmd, true);
} else if (shizuku.isOperational()) {
r = shizuku(cmd);
} else {
r = null;
}
if (r == null || r.code !== 0) return false;
return r.result.includes(`package:${packageName}`);
}
// 使用示例:
const pkg = App.ALIPAY.packageName;
const hasDual = isDualInstalled(pkg);
toastLog(`分身是否存在 (${pkg}): ${hasDual}`);
必须root或者shizuku权限才能判断吗?
app.launchDual() app.launchDualPackage() app.launchDualApp() app.launchDualSettings() app.openDualAppSetting() app.uninstallDual() app.killDual()
这些分身相关的函数是否也是依赖root或者shizuku?