Is this the correct way to set a daily (inexact) alarm via a BootReceiver?
import java.util.Calendar;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
public class BootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
SharedPreferences sp =
context.getSharedPreferences("MYPREFS",Context.MODE_PRIVATE);
int alarmHour = sp.getInt("HOUR", 15); // Noon+3h
int alarmMin= sp.getInt("MINUTE", 0);
Calendar calAlarm = Calendar.getInstance();
calAlarm.setTimeInMillis(System.currentTimeMillis());
calAlarm.set(Calendar.HOUR_OF_DAY, alarmHour);
calAlarm.set(Calendar.MINUTE, alarmMin);
AlarmManager am = (AlarmManager)
context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, MyReceiver.class);
PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
am.setInexactRepeating(AlarmManager.RTC, calAlarm.getTimeInMillis(),
AlarmManager.INTERVAL_DAY, pi);
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en