请教:经常没反应=>app.launchApp("某音")

在vscode调试时,有时能打开,有时不能?请问怎么办?

app.launch(packageName) 用这个试试

手机桌面打不开app,但仍然会返回true,只有在autox界面的时候 才能打开其它app,咋回事

解决了吗?老铁。。。

@786851606 确实,我的手机也是这样,红米手机,但是在模拟器就没问题

function qdapp(packageName, name) {
  home();
  sleep(500);
  if (app.launch(packageName)) {
    sleep(5000);
    toast("成功启动=" + name);
    console.log("启动currentPackage=" + currentPackage());
    console.log("启动currentActivity=" + currentActivity());
    if (currentPackage() != packageName) {
      sleep(500);
      launch(packageName);
      sleep(5000);
    }
    var i = 1;
    while (currentPackage() != packageName) {
      sleep(1000);
      console.log("检测到没有启动,所以进入循环状态去启动!!!");
      console.log("启动currentPackage=" + currentPackage());
      var jmapp = className("android.widget.TextView").text(name).find();
      if (!jmapp.empty() && jmapp.length) {
        console.log("获取=" + jmapp[0].clickable());
        if (jmapp[0].clickable() == true && i == 1) {
          jmapp[0].clicK();
        }
        if (jmapp[0].clickable() == false && i == 1) {
          var bounds = jmapp[0].parent().bounds();
          var centerX = (bounds.left + bounds.right) / 2;
          var centerY = (bounds.top + bounds.bottom) / 2;
          click(centerX, centerY);
        }
      }

      var jmapp2 = className("android.widget.TextView").desc(name).find();
      if (!jmapp2.empty() && jmapp2.length) {
        console.log("获取=" + jmapp2[0].clickable());
        if (jmapp2[0].clickable() == true && i == 2) {
          jmapp2[0].clicK();
        }
        if (jmapp2[0].clickable() == false && i == 2) {
          var bounds = jmapp2[0].parent().bounds();
          var centerX = (bounds.left + bounds.right) / 2;
          var centerY = (bounds.top + bounds.bottom) / 2;
          click(centerX, centerY);
        }
      }

      if (currentPackage() != packageName && i == 3) {
        toast("无法启动,请把" + name + "图标放到主页,或者自己手动打开。");
        i = 1;
      }
      i += 1;
      sleep(5000);
      console.log("启动currentPackage=" + currentPackage());
    }

  } else {

    toast("失败,请查看是否有开启权限!" + packageName);
  }

  




}
 


其中:packageName=启动app的包名, name=app桌面上的名称,启动的地方调用这个函数即可,但是要把app的图标都放到home主页去。