Android IntentService无法在启动时启动

时间:2013-05-21 13:44:33

标签: android android-intent broadcastreceiver boot intentservice

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

清单:

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

1 个答案:

答案 0 :(得分:2)

尝试更改

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

in

<receiver android:name=".RastreadorBroadcastReceiver" >