1

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);
    }
}
Piovezan
  • 3,215
  • 1
  • 28
  • 45
  • Does your Receiver get the Intent? I mena, does your onReceive method get called? – edoardotognoni May 21 '13 at 13:48
  • I can't debug to verify since it's not an activity. How do I check? – Piovezan May 21 '13 at 13:58
  • before creating the startServiceIntent just add: Log.d("DEBUG", "Creating the intent"); and see if this string is written to the logcat – edoardotognoni May 21 '13 at 14:13
  • For Log.d() to work the debugger must be attached to the process, which doesn't happen in this case. I'm following the instructions on http://stackoverflow.com/questions/4008081/debugging-a-service but the debugger doesn't seem to attach either. – Piovezan May 21 '13 at 14:24
  • No. To use the Log class you don't need the debugger to be attacched. Are you using Eclipse? If so, open the DDMS perspective view, and you will get the logcat view. Inside that there are all the logs. Log.d simply writes a string to the logcat – edoardotognoni May 21 '13 at 14:25
  • Okay, thanks. The debug message is not being printed. – Piovezan May 21 '13 at 14:44

1 Answers1

2

try changing

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

in

<receiver android:name=".RastreadorBroadcastReceiver" >
edoardotognoni
  • 2,752
  • 3
  • 22
  • 31