ADB命令行启动活动权限

时间:2017-03-16 13:56:03

标签: android android-intent adb

我正在尝试使用命令行上的adb使用意图触发活动:

adb shell am start 
 -a android.intent.action.VIEW 
 -c android.intent.category.DEFAULT 
 -t vnd.google.android.package/vnd.google.android.package_something 
 -n com.google.android.package/com.google.android.apps.package.SomeActivity

但它会抛出一个安全例外:

Starting: Intent { act=android.intent.action.VIEW cat=[android.intent.category.DEFAULT] typ=vnd.google.android.package/vnd.google.android.package_something cmp=com.google.android.package/com.google.android.apps.package.SomeActivity }
java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.VIEW cat=[android.intent.category.DEFAULT] typ=vnd.google.android.package/vnd.google.android.package_something flg=0x10000000 cmp=com.google.android.package/com.google.android.apps.package.SomeActivity } from null (pid=31536, uid=2000) requires com.google.android.package.START_ACTIVITY
        at android.os.Parcel.readException(Parcel.java:1620)
        at android.os.Parcel.readException(Parcel.java:1573)
        at android.app.ActivityManagerProxy.startActivityAsUser(ActivityManagerNative.java:2767)
        at com.android.commands.am.Am.runStart(Am.java:885)
        at com.android.commands.am.Am.onRun(Am.java:361)
        at com.android.internal.os.BaseCommand.run(BaseCommand.java:47)
        at com.android.commands.am.Am.main(Am.java:101)
        at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
        at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:251)

所以我再次尝试了缺少权限的用户:

adb shell am start 
  -a android.intent.action.VIEW -c android.intent.category.DEFAULT 
  -t vnd.google.android.package/vnd.google.android.package_something 
  -n com.google.android.package/com.google.android.apps.package.SomeActivity 
  --user 10088

然后它说活动不存在:

Starting: Intent { act=android.intent.action.VIEW cat=    [android.intent.category.DEFAULT] typ=vnd.google.android.package/vnd.google.android.package_something cmp=com.google.android.package/com.google.android.apps.package.SomeActivity }
Error type 3
Error: Activity class {com.google.android.package/com.google.android.apps.package.SomeActivity} does not exist.

我是否错误地使用了用户参数?我是否需要提供更多信息?

1 个答案:

答案 0 :(得分:0)

您应该使用以下语法开始活动:

adb shell am start  
-n com.google.android.package/.SomeActivity

在您拥有用户权限的情况下:

adb shell am start  
-n com.google.android.package/.SomeActivity
--user 10088