1

我有一个 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);
    }
}
4

1 回答 1

2

尝试改变

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

<receiver android:name=".RastreadorBroadcastReceiver" >
于 2013-05-21T15:24:51.963 回答