Android Can';不要启动外部服务

Android Can';不要启动外部服务,android,service,Android,Service,我在应用程序A中有一个IntentService,我正试图从应用程序B开始。当我运行时 ActivityManager: Unable to start service Intent { cmp=com.xyz/.service.MyIntentService } U=0: not found 这是我在应用程序A中的IntentService代码 package com.xyz.service; import android.app.IntentService; import android

我在应用程序A中有一个IntentService,我正试图从应用程序B开始。当我运行时

ActivityManager: Unable to start service Intent { cmp=com.xyz/.service.MyIntentService } U=0: not found
这是我在应用程序A中的IntentService代码

package com.xyz.service;

import android.app.IntentService;
import android.content.Intent;
import android.util.Log;

public class MyIntentService extends IntentService {
    public MyIntentService() {
        super("MyIntentService");
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        Log.i("MyIntentService", "Intent Started");
    }
}
在应用程序B的主要活动中,我有以下内容

Intent i = new Intent();
i.setComponent(new ComponentName("com.xyz", "com.xyz.service.MyIntentService"));
startService(i);
我还在应用程序A的AndroidManifest.xml中声明了该服务

<service android:name=".service.MyIntentService" android:enabled="true" android:exported="true"></service>
<permission android:name="com.xyz.permission.PERMISSION_NAME"
            android:protectionLevel="signature"/>
<uses-permission android:name="com.xyz.permission.PERMISSION_NAME"/>

<service android:name=".service.MyIntentService"
             android:enabled="true"
             android:exported="true"
             android:permission="com.xyz.permission.PERMISSION_NAME"/>
<uses-permission android:name="com.xyz.permission.PERMISSION_NAME"/>


任何帮助都将不胜感激。

在文件A的AndroidManifest.xml中,尝试以下操作:

<service
           android:enabled="true"
           android:exported="true"
           android:name=".service.MyIntentService">
        <intent-filter>
            <action android:name="com.xyz.START_SERVICE" />
        </intent-filter>
</service>

在文件A的AndroidManifest.xml中,尝试以下操作:

<service
           android:enabled="true"
           android:exported="true"
           android:name=".service.MyIntentService">
        <intent-filter>
            <action android:name="com.xyz.START_SERVICE" />
        </intent-filter>
</service>

您应该在AndroidManifest.xml中声明权限

<service android:name=".service.MyIntentService" android:enabled="true" android:exported="true"></service>
<permission android:name="com.xyz.permission.PERMISSION_NAME"
            android:protectionLevel="signature"/>
<uses-permission android:name="com.xyz.permission.PERMISSION_NAME"/>

<service android:name=".service.MyIntentService"
             android:enabled="true"
             android:exported="true"
             android:permission="com.xyz.permission.PERMISSION_NAME"/>
<uses-permission android:name="com.xyz.permission.PERMISSION_NAME"/>

并在B AndroidManifest.xml中添加用户权限

<service android:name=".service.MyIntentService" android:enabled="true" android:exported="true"></service>
<permission android:name="com.xyz.permission.PERMISSION_NAME"
            android:protectionLevel="signature"/>
<uses-permission android:name="com.xyz.permission.PERMISSION_NAME"/>

<service android:name=".service.MyIntentService"
             android:enabled="true"
             android:exported="true"
             android:permission="com.xyz.permission.PERMISSION_NAME"/>
<uses-permission android:name="com.xyz.permission.PERMISSION_NAME"/>

您应该在A AndroidManifest.xml中声明权限

<service android:name=".service.MyIntentService" android:enabled="true" android:exported="true"></service>
<permission android:name="com.xyz.permission.PERMISSION_NAME"
            android:protectionLevel="signature"/>
<uses-permission android:name="com.xyz.permission.PERMISSION_NAME"/>

<service android:name=".service.MyIntentService"
             android:enabled="true"
             android:exported="true"
             android:permission="com.xyz.permission.PERMISSION_NAME"/>
<uses-permission android:name="com.xyz.permission.PERMISSION_NAME"/>

并在B AndroidManifest.xml中添加用户权限

<service android:name=".service.MyIntentService" android:enabled="true" android:exported="true"></service>
<permission android:name="com.xyz.permission.PERMISSION_NAME"
            android:protectionLevel="signature"/>
<uses-permission android:name="com.xyz.permission.PERMISSION_NAME"/>

<service android:name=".service.MyIntentService"
             android:enabled="true"
             android:exported="true"
             android:permission="com.xyz.permission.PERMISSION_NAME"/>
<uses-permission android:name="com.xyz.permission.PERMISSION_NAME"/>


不幸的是,这不起作用。抛出IllegalArgumentException,说明服务意图必须明确。添加intent.setPackage(“com.xyz”)后,会出现最初的ActivityManager错误。感谢您,它成功了。原来我的包裹清单上也有一个打字错误。太好了!如果有帮助,请随意将其标记为答案:)不幸的是,这不起作用。抛出IllegalArgumentException,说明服务意图必须明确。添加intent.setPackage(“com.xyz”)后,会出现最初的ActivityManager错误。感谢您,它成功了。原来我的包裹清单上也有一个打字错误。太好了!如果有帮助,请随意将其标记为答案:)adb shell dumpsys package com.xyz命令的输出是什么?您也可以尝试:
adb shell pm dump com.xyz
并且输出更加详细-因此首先尝试
adb shell dumpsys…
谢谢!!原来我的包名有一个输入错误。如果没有这个命令,可能不会捕获它。
adb shell dumpsys package com.xyz
命令的输出是什么?您也可以尝试:
adb shell pm dump com.xyz
并且输出更加详细-因此首先尝试
adb shell dumpsys…
谢谢!!原来我的包名有一个输入错误。如果没有这个命令,可能不会抓到它。