Android IntentService 不会在开机时启动

标签 android android-intent broadcastreceiver boot intentservice

我有一个 IntentService,它在启动时启动并在后台保持运行。没有启动器 Activity,IntentService 由广播接收器调用。它适用于 2.3.4 和 4.0.4 设备,但不适用于 4.2.2。也许我的广播接收器没有在设备上触发?

list :

<?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);
    }
}

最佳答案

尝试改变

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

<receiver android:name=".RastreadorBroadcastReceiver" >

关于Android IntentService 不会在开机时启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16671619/

相关文章:

android - 在 Mac OS X 上制作/构建 mupdf 时出错

java - Parse.com Android API 和 Android 对话框

android - 从 RAM 中清除应用程序时广播接收器不工作

android - 单击android通知图标不会触发广播接收器

android - Camera intent resultCode 总是返回取消牛轧糖

android - 为什么这个广播接收器在 Android Lollipop 中不起作用?

android - 创建通知

android - Android 上的文件描述符的最大数量是多少?

android - getContext 和 getResource 在 5.0 及更低版本之间的兼容性

Android:从preferences.xml 启动Activity