[英]Android adb shell am startservice: Error not found
我正在嘗試從 adb shell 啟動服務。 已經有類似的問題: How to start and stop android service from a adb shell? 但是,當我開始服務時:
adb shell am startservice com.mypackage/com.mypackage.service.MyService
我收到這條消息:
Starting service: Intent { act=android.intent.action.VIEW dat=com.mypackage/com.mypackage.service.MyService }
Error: Not found; no service started.
我在 AndroidManifest.xml 中聲明服務:
<application>
...
<service
android:name="com.mypackage.service.MyService"
android:label="@string/local_service_label"
android:icon="@drawable/ic_launcher">
</service>
</application>
你知道如何解決這個問題嗎? 謝謝!
adb shell am startservice -n com.mypackage/.service.MyService
更新(每個adb shell am help start-service
):
-n
<COMPONENT_NAME>
以下面為例
<application android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
android:theme="@style/AppTheme">
<service
android:name=".MyService"
android:description="@string/Desciption"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.nandhan.myservice" />
</intent-filter>
</service>
</application>
然后我將啟動服務如下
adb shell am startservice com.nandhan.myservice/.MyService
就我而言,無法啟動的服務是com.android.tools.fd.runtime.InstantRunService
。
啟動服務: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.xxx.xxx/com.android.tools.fd.runtime.InstantRunService } 錯誤:未找到; 沒有服務啟動。
原來我的安卓設備丟失了一些東西。 要禁用它,請轉到preferences > Build, Execution, Deployment > Instant Run
並取消選中Enable Instant Run to hot swap code/resource changes on deploy (default enabled)
。
根據那個截圖,最好保留它,事實上,我會對這個功能更滿意。 至少我運行了額外的日志記錄並向谷歌發送了反饋。 我只需要盡快構建,所以今天我沒有立即運行;)
顯現:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.xyz.path">
...
<application
...
<service android:name=".MyService">
<intent-filter>
<action android:name="com.xyz.path.MY_SERVICE" />
</intent-filter>
</service>
...
命令:
adb shell am startservice -n com.xyz.path/.MyService
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.