Android的IntentService不会开机启动Android、IntentService

2023-09-05 10:55:11 作者:不酷但很软

我有开始在引导和保持在后台运行的IntentService。没有发射活动,所述IntentService称为由广播接收器。它适用于2.3.4和4.0.4设备,但不能在4.2.2。也许我的广播接收器没有被触发设备上?

清单:

 < XML版本=1.0编码=UTF-8&GT?;
<舱单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    包=br.com.xxx
    安卓版code =1
    机器人:VERSIONNAME =1.0>

    <用途-SDK
        安卓的minSdkVersion =8
        机器人:targetSdkVersion =17/>

    <使用-权限的Andr​​oid:名称=android.permission.ACCESS_FINE_LOCATION/>
    <使用-权限的Andr​​oid:名称=android.permission.INTERNET对/>
    <使用-权限的Andr​​oid:名称=android.permission.READ_PHONE_STATE/>
    <使用-权限的Andr​​oid:名称=android.permission.RECEIVE_BOOT_COMPLETED/>

    <应用
        机器人:allowBackup =真
        机器人:图标=@可绘制/ ic_launcher
        机器人:标签=@字符串/ APP_NAME
        机器人:主题=@风格/ AppTheme>

        <接收器的Andr​​oid版本:NAME =br.com.xxx.RastreadorBroadcastReceiver>
            <意向滤光器>
                <作用机器人:名称=android.intent.action.BOOT_COMPLETED/>
            &所述; /意图滤光器>
        < /接收器>

        <服务
            机器人:名称=br.com.xxx.ObtainAndPostLocationService
            机器人:出口=真正的>
        < /服务>

    < /用途>

< /舱单>
 

RastreadorBroadcastReceiver:

 包br.com.xxx;

进口android.content.BroadcastReceiver;
进口android.content.Context;
进口android.content.Intent;

公共类RastreadorBroadcastReceiver扩展的BroadcastReceiver {

    @覆盖
    公共无效的onReceive(上下文的背景下,意图意图){
        意图startServiceIntent =新的意图(背景下,ObtainAndPostLocationService.class);
        context.startService(startServiceIntent);
    }
}
 

解决方案

请尝试更改

<接收器的Andr​​oid版本:NAME =br.com.xxx.RastreadorBroadcastReceiver>

Android入门 5 Intent的使用

 <接收机器人:名称=。RastreadorBroadcastReceiver>
 

I have an IntentService which starts on boot and stays running in the background. There is no launcher Activity, the IntentService is called by a broadcast receiver. It works on 2.3.4 and 4.0.4 devices but not on 4.2.2. Maybe my broadcast receiver isn't being triggered on the device?

Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="br.com.xxx"
    android:versionCode="1"
    android:versionName="1.0">

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <receiver android:name="br.com.xxx.RastreadorBroadcastReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>

        <service
            android:name="br.com.xxx.ObtainAndPostLocationService"
            android:exported="true">
        </service>

    </application>

</manifest>

RastreadorBroadcastReceiver:

package br.com.xxx;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class RastreadorBroadcastReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Intent startServiceIntent = new Intent(context, ObtainAndPostLocationService.class);
        context.startService(startServiceIntent);
    }
}

解决方案

try changing

<receiver android:name="br.com.xxx.RastreadorBroadcastReceiver" >

in

<receiver android:name=".RastreadorBroadcastReceiver" >