Android adb shell am startservice:未找到错误
我正在尝试从adb shell启动服务。已经有类似的问题: 但是,当我开始服务时:Android adb shell am startservice:未找到错误,android,adb,Android,Adb,我正在尝试从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
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帮助启动服务):
-n
以下面的例子为例
<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>
然后,我将启动以下服务
亚行壳牌am startservice com.nandhan.myservice/.myservice清单:
<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>
...
在我的例子中,未能启动的服务是
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}
错误:未找到;没有启动任何服务
结果发现我的android设备遗漏了一些东西。要禁用它,请转到首选项>生成、执行、部署>即时运行
并取消选中启用即时运行以在部署时热插拔代码/资源更改(默认启用)
根据那个截图,最好保留它,事实上,我会更喜欢这个功能。至少我运行了额外的日志记录并向谷歌发送了反馈。我只是需要尽快构建,所以今天我没有即时运行;) 一个命令可以回答这个问题,但是解释
-n
的作用会很有用。您可能还希望将任何代码缩进4个空格。“am startservice”帮助列表[-n](它与行号无关)
adb shell am startservice -n com.xyz.path/.MyService