我創建了簡單的android application,其中包含一項活動和服務。該服務由aidl
文件定義,並且可以通過Binder
接收來自該活動的呼叫。一切都按預期工作。通過adb發送消息給定製服務
現在我部署(還我試着仿真器)設備上的應用程序,我想通過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
發送消息給我的服務?
似乎它的系統服務只有:http://stackoverflow.com/questions/12157442/android-emulator-how-can-i-get -a-list-of-services-that-are-running#comment63723794_24208845,我找不到我的服務以及使用'服務列表' – pskink
,如果'adb shell startservice'工作正常,然後用它將消息傳遞給你的服務 – pskink
@pskink,你能展示如何使用'startservice'傳遞消息嗎? – Gluttton