android - 非导出 Activity : launched on emulators; SecurityException on phones

标签 android android-activity android-emulator adb root

我的项目中有一个未导出的 Activity

如果我尝试使用 adb 在我的手机上启动它:

adb shell am start -n "packagename/activityname"

我得到错误:

java.lang.SecurityException:
Permission Denial: starting Intent { ... } from null (...) not exported from uid ...

但是,如果我在模拟器上运行相同的命令,那么一切正常。怎么来的?

最佳答案

But, if I run the same command on an emulator, then everything works Okay. How comes?

模拟器实例默认以 root 身份运行,这意味着与非 root 设备相比,更多的系统进程具有 root 权限。

考虑使用 adbdsh 编辑 ps 命令输出 grep(即 adb shell ps | grep 'adbd'adb shell ps | grep 'sh')。您可能会看到以下内容(当然,您的设备/模拟器上有不同的 PIDPPID):

  • 非root设备

    USER     PID   PPID  NAME
    shell    166   1     /sbin/adbd
    ...
    shell    15721 166   /system/bin/sh
    
  • 模拟器

    USER     PID   PPID  NAME
    root     1183  1     /sbin/adbd
    ...
    root     2884  1183  /system/bin/sh
    

sh 进程及其父进程 adbd 在模拟器上由 root 拥有,与 shell 形成对比 非根设备上的所有者。尽管 android:exportedroot 用户拥有访问您应用程序沙盒的“权限”。属性设置为 false

关于android - 非导出 Activity : launched on emulators; SecurityException on phones,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37075351/

相关文章:

Android - 带图像的布局

java - AndEngine GenericPool 带有计时器,从池中添加 Sprite

android - "leaking the Activity"是什么意思,我该如何预防?

java - 调用 putExtra 时 Activity 未完成

android - 显示 html 标签的 Webview 不是实际需要的数据?

android - 打开 GPS 时出现异常

android - 防止在随机模式下重复

java - android:如何更改按钮点击布局?

Android 测试未执行

android - 关于 Android 编程的快速问题