11

我正在尝试从 adb shell 启动服务。已经有类似的问题:How to start and stop android service from 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>

你知道如何解决这个问题吗?谢谢!

4

4 回答 4

16
adb shell am startservice -n com.mypackage/.service.MyService

更新(每adb shell am help start-service):

-n <COMPONENT_NAME>

于 2012-09-20T07:21:41.657 回答
4

以以下为例

<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

于 2013-06-10T07:47:24.807 回答
4

就我而言,无法启动的服务是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)

禁用即时运行

根据该屏幕截图,最好保留它,事实上,我会更喜欢该功能。至少我运行了额外的日志并将反馈发送给谷歌。我只需要尽快构建,所以今天没有立即运行;)

于 2017-04-24T19:21:56.827 回答
1

显现:

<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
于 2015-08-20T12:44:18.080 回答