adb startservice 启动服务出现异常,安卓4.X

adb  -s 52009c91f86932c1  shell am startservice  com.cmrx.xckyservice/.xckyservice
Starting service: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.cmrx.xckyservice/.xckyservice }
java.lang.SecurityException: Caller uid=2000 is not privileged to communicate with user=-2
        at android.os.Parcel.readException(Parcel.java:1431)
        at android.os.Parcel.readException(Parcel.java:1385)
        at android.app.ActivityManagerProxy.startService(ActivityManagerNative.java:3014)
        at com.android.commands.am.Am.runStartService(Am.java:538)
        at com.android.commands.am.Am.onRun(Am.java:234)
        at com.android.internal.os.BaseCommand.run(BaseCommand.java:47)
        at com.android.commands.am.Am.main(Am.java:75)
        at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
        at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:297)

        at dalvik.system.NativeStart.main(Native Method)

发现在三星4.3和4.2系统上会出现如上bug,拉不起来自己服务其他设备没有问题。

解决方法为指定用 user=0 来调用命令即可:

am startservice --user 0 -a 

示例:

adb  -s 52009c91f86932c1  shell am startservice --user 0 -n com.cmrx.xckyservice/.xckyservice

你可能感兴趣的:(Android)