【问题标题】:Android adb shell am startservice: Error not foundAndroid adb shell am startservice:找不到错误
【发布时间】:2012-09-10 07:58:05
【问题描述】:

我正在尝试从 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>

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

【问题讨论】:

    标签: android adb


    【解决方案1】:
    adb shell am startservice -n com.mypackage/.service.MyService
    

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

    -n&lt;COMPONENT_NAME&gt;

    【讨论】:

    • 一个命令可能会回答这个问题,但解释一下-n 的作用会很有用。您可能还想将任何代码缩进 4 个空格。
    • "am startservice" 帮助列表 [-n ](与行号无关)
    【解决方案2】:

    以下面为例

    <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

    【讨论】:

      【解决方案3】:

      在我的例子中,服务启动失败是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 &gt; Build, Execution, Deployment &gt; Instant Run 并取消选中 Enable Instant Run to hot swap code/resource changes on deploy (default enabled)

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

      【讨论】:

        【解决方案4】:

        清单:

        <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
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2011-07-07
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2022-08-27
          • 2011-10-09
          • 2013-12-12
          • 1970-01-01
          相关资源
          最近更新 更多