【发布时间】:2017-10-13 11:51:15
【问题描述】:
我创建了简单的 android application,其中包含一个活动和服务。该服务由aidl 文件定义,并且可以通过Binder 接收来自活动的调用。一切正常。
现在我在设备上部署应用程序(我也尝试过模拟器),我想通过adb向服务发送消息:
$ adb shell service call \
com.example.gluttton.dummyandroid/.DummyService 0 STR "Bingo!"
并收到消息说此类服务不存在:
服务:服务 com.example.gluttton.dummyandroid/.DummyService 确实 不存在
我尝试检查我的服务是否启动:
$ adb shell service list
或
$ adb shell service check com.example.gluttton.dummyandroid/.DummyService
得到了类似的结果。
但与此同时,我使用dumpsys 看到我的服务:
$ adb shell dumpsys activity services Dummy
ACTIVITY MANAGER SERVICES (dumpsys activity services)
User 0 active services:
* ServiceRecord{a1627b5 u0 com.example.gluttton.dummyandroid/.DummyService}
intent={act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.gluttton.dummyandroid/.DummyService}
packageName=com.example.gluttton.dummyandroid
processName=com.example.gluttton.dummyandroid
baseDir=/data/app/com.example.gluttton.dummyandroid-1/base.apk
dataDir=/data/data/com.example.gluttton.dummyandroid
app=ProcessRecord{114da04c 20168:com.example.gluttton.dummyandroid/u0a126}
createTime=-21m40s817ms startingBgTimeout=--
lastActivity=-21m40s816ms restartTime=-21m40s816ms createdFromFg=true
startRequested=true delayedStop=false stopIfKilled=false callStart=true lastStartId=1
我也可以启动我的服务:
$ adb shell am startservice com.example.gluttton.dummyandroid/.DummyService
Starting service: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.gluttton.dummyandroid/.DummyService }
然后停止它:
$ adb shell am stopservice com.example.gluttton.dummyandroid/.DummyService
Stopping service: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.gluttton.dummyandroid/.DummyService }
Service stopped
所以我的问题是我的错误在哪里以及如何通过adb 向我的服务发送消息?
【问题讨论】:
-
似乎它仅用于系统服务:stackoverflow.com/questions/12157442/…,我也无法使用
service list找到我的服务 -
如果
adb shell am startservice有效,则使用它将消息传递给您的服务 -
@pskink,你能展示如何使用
startservice传递消息吗?
标签: android