0

I want to run a repeating alarm, starting at system boot. This is the code:

// Run the SendService once an hour
@Override
public void onReceive(Context context, Intent intent) {
    //Logger.getInstance().writeLine(getClass().getName(), "Received boot, start SMS repeating alarm");
    Toast.makeText(context, "Starting SMS2Mail alarm on boot", Toast.LENGTH_LONG).show();
    Intent svcIntent = new Intent(context, MessageFileService.class);
    svcIntent.setAction(MessageFileService.GET_INTENT);
    sendSMSIntent = PendingIntent.getBroadcast(context, 0, svcIntent, 0);
    alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
            AlarmManager.INTERVAL_FIFTEEN_MINUTES,
            AlarmManager.INTERVAL_HOUR, sendSMSIntent);
}

The manifest has

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

and

 <service
        android:name="com.cio1.sms2mail.StartSendService"
        android:enabled="true"
        android:exported="true" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </service>

The AlarmManager does not fire at all, as far as any of my debugging resources can tell me. Also, any clues as to how to recover the LogCat information from boot time would help. Also, does this have to do with the restriction on broadcast receivers mentioned here? Thanks.

Community
  • 1
  • 1
Aharon Manne
  • 712
  • 3
  • 11
  • 34

1 Answers1

0

Several thoughts

I see service tag in your manifest. Shouldn't it be a receiver? In all tutorials I have seen BOOT_COMPLETE was captured by receiver, which in turn,started the AlarmManager.

Second, to receive onboot intent application must be started manually at least once.

Eugene
  • 656
  • 8
  • 20