hi i have an alarm manager and user sets the alarms and i save that into a database for when the phone reboot or boot i write this so far but its not working
public class RestartAlarmsReceiver extends BroadcastReceiver {
private static final String TAG = "alarm";
AlarmManager alarmManager;
Intent mintent;
PendingIntent pendingIntent;
AlarmDbHelper dbHelper;
long time;
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")|| intent.getAction().
equals("android.intent.action.REBOOT")) {
dbHelper = new AlarmDbHelper(context);
List<ChildTour> alarms =dbHelper.getAlarms();
for (int i =0;i<2;i++){
alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
mintent = new Intent(context,AlarmReceiver.class);
ChildTour Child = alarms.get(i);
mintent.putExtra("name",Child.getTime());
mintent.putExtra("tourId",Child.getTourId()+"");
pendingIntent = PendingIntent.getBroadcast(context,Child.getTourId(),mintent,0);
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, Child.getHour());
calendar.set(Calendar.MINUTE, Child.getMin());
time=(calendar.getTimeInMillis()-(calendar.getTimeInMillis()%60000));
if(System.currentTimeMillis()>time)
{
if (calendar.AM_PM == 0)
time = time + (1000*60*60*12);
else
time = time + (1000*60*60*24);
}
alarmManager.set(AlarmManager.RTC_WAKEUP,time, pendingIntent);
Log.i("alarm","Alarm set With Id : "+Child.getTourId() +"Hour: " +Child.getHour()+"Minute: "+Child.getMin());
}
}
}
and this is my manifests file i try Reboot and Turn off on my phone and that not working
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<receiver android:name=".AlarmReceiver"/>
<receiver android:name=".RestartAlarmsReceiver"
android:enabled="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.REBOOT"/>
<action android:name="android.intent.action.ACTION_POWER_CONNECTED"/>
</intent-filter>
</receiver>
and my alarmReciver class is working