I want my alarm(s) to resume/restart after the device is rebooted. After a lot of research on Google I found that it doesnt work without saving the alarms to the database. I have 2 questions:
2.How am I supposed to read the alarms from the database on reboot since the BOOT_COMPLETED intent isnt received by the broadcastreceiver.
1.How do I save the alarms to the database (How do I know that the DB is created and the values are inserted)?
EDIT:
I already have the necessary permission and receiver and this code: Tell me what to change in this code? MainActivity.java
onClick:
int intHrs = SetResetIntervalActivity.intHours;
int intMins = SetResetIntervalActivity.intMinutes;
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, intHrs);
calendar.set(Calendar.MINUTE, intMins);
calendar.set(Calendar.SECOND, 0);
Intent myIntent = new Intent(
"com.sang.mobiledata.IntentAction.RECEIVE_RESETCONN_UPDATE");
myIntent.putExtra("FLAG_KEY", false);
PendingIntent pi = PendingIntent.getBroadcast(this, 0, myIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) this
.getSystemService(Context.ALARM_SERVICE);
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.SECOND, 10);
long interval = intHrs * 3600000 + intMins * 60000;
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
calendar.getTimeInMillis(), interval, pi);
long mins = interval / 60000;
Toast.makeText(
MainActivity.this,
"Data Connection will be reset every " + mins
+ " minute(s).", Toast.LENGTH_SHORT).show();
broadcast receiver:
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equalsIgnoreCase(
"android.intent.action.BOOT_COMPLETED")) {
//control never enters here
boolean blnVar=true;
blnVar=false;
....
Manifest:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<receiver
android:name="com.sang.mobiledata.ResetBroadcastReceiver"
android:exported="true" >
<intent-filter>
<action android:name="com.sang.mobiledata.IntentAction.RECEIVE_RESETCONN_UPDATE" />
</intent-filter>
<intent-filter>
<action android:name="com.sang.mobiledata.IntentAction.BOOT_COMPLETED" />
</intent-filter>
</receiver>