android - 无法启动服务 Intent

标签 android service android-intent intentfilter

我有一个服务类。我已将此类导出到 jar,并将 jar 嵌入到我的客户端应用程序中。

当需要时,我调用服务类。当我尝试这样做时,我收到以下错误:

Unable to start service Intent {comp={com.sample.service/com.sample.service.serviceClass}} : not found

除了服务类之外,我还有其他类,我可以访问(创建该类的对象)它们在同一个 jar 中。

我觉得我在配置或 list 中遗漏了一些东西。

请帮助我识别相同的内容。我的代码如下:

public void onCreate(Bundle savedInstanceState) {    
      super.onCreate(savedInstanceState);  
      Intent intent = new Intent () ;  
      intent.setClassName("com.sample.service" ,"com.sample.service.serviceClass") ;  
      this.startService(intent) ; // when I call this line I get the message...  
      // binding other process continue  here   
}

客户端 list .xml

<service android:name="com.sample.service.serviceClass"  
            android:exported="true" android:label="@string/app_name" 
            android:process=":remote">
   <intent-filter><action android:name="com.sample.service.serviceClass"></action>
   </intent-filter>
</service>

提前致谢,
维奈

最佳答案

对于遇到此线程的其他人,我遇到了这个问题并且正在拔头发。 我在 '' 结束标记 DUH 之外有服务声明!

右:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  ...>
...
<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity ...>
        ...
    </activity>    

    <service android:name=".Service"/>

    <receiver android:name=".Receiver">
        <intent-filter>
            ...
        </intent-filter>
    </receiver>        
</application>

<uses-permission android:name="..." />

错误但仍然编译没有错误:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  ...>
...
<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity ...>
        ...
    </activity>

</application>

    <service android:name=".Service"/>

    <receiver android:name=".Receiver">
        <intent-filter>
            ...
        </intent-filter>
    </receiver>        

<uses-permission android:name="..." />

关于android - 无法启动服务 Intent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3439356/

相关文章:

java - 为什么 LinearLayout 子 getWidth 方法返回 0?

android - firebaseAppDistribution - 方法 : build. android() 的无签名适用于参数类型:(build_run_closure1) 值:[build_run_closure1@x

java - 无响应的 HTTP 处理程序

c# - 确定解决方案配置 (Visual Studio)

android - 在 EditText 数组上禁用 Android 键盘

android - 我在 Google Play 上看不到我的应用程序

android - 如何国际化 ic_launcher 图标?

android - 如何使用 Hilt 将 SharedPreferences 注入(inject)后台服务

android - 从 RecyclerView Adapter 开始新的 Intent

android - 发送 Intent 的进程的 Pid