You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

非Root安卓设备执行am启动Activity命令遇权限问题求解决方案

非Root设备本地启动指定Display的Yandex导航Activity解决方案

问题原因

你在设备终端执行命令失败,是因为终端应用的UID(10211)属于普通应用权限组,com.android.shell没有跨Display启动其他应用Activity的权限;而adb shell使用的是shell用户(UID=2000),拥有更高的系统权限,所以能正常执行。

可行方案

方案1:编写自定义安卓应用调用系统API

自己写一个极简应用,用应用自身权限调用ActivityManager的API来启动目标Activity,无需Root:

  1. 创建安卓项目,在主Activity中添加以下代码:
import android.content.ComponentName;
import android.content.Intent;
import android.app.Activity;
import android.app.ActivityManager;
import android.os.Bundle;
import android.os.UserHandle;

public class LaunchNaviActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        // 构造启动Yandex导航的Intent
        Intent naviIntent = new Intent();
        naviIntent.setComponent(new ComponentName(
            "ru.yandex.yandexnavi", 
            "ru.yandex.yandexnavi.core.NavigatorActivity"
        ));
        naviIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        // 获取ActivityManager实例,指定Display 2启动
        ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
        try {
            activityManager.startActivityInPackage(
                0, 
                naviIntent, 
                null, 
                null, 
                null, 
                0, 
                null, 
                null, 
                UserHandle.CURRENT, 
                2 // 指定Display ID
            );
        } catch (Exception e) {
            e.printStackTrace();
        }

        finish(); // 启动后自动关闭当前应用
    }
}
  1. 编译安装该应用,运行即可触发目标Activity在Display 2启动(无需额外权限,只要Yandex导航的目标Activity允许外部启动)。

方案2:借助adb远程触发(需保持设备与电脑连接)

如果可以保持设备和电脑的adb连接,直接在电脑端执行命令即可,比设备端操作更稳定:

adb shell am start-activity --display 2 ru.yandex.yandexnavi/.core.NavigatorActivity

可以把这个命令写成批处理/脚本,一键执行。

方案3:使用第三方无Root快捷工具

部分第三方快捷方式制作应用(如Shortcut Maker)支持自定义启动参数:

  1. 安装这类工具,选择「创建Activity快捷方式」
  2. 输入包名ru.yandex.yandexnavi和类名ru.yandex.yandexnavi.core.NavigatorActivity
  3. 在参数设置中添加启动Display的配置(部分工具支持直接指定display ID或添加--display 2参数)
  4. 创建快捷方式后,点击即可启动指定Display的导航。

内容的提问来源于stack exchange,提问作者user16684645

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 19:03:15