Issue with Alarm wakeup after phone restart and switch off and on!

  • Replies:1
  • OpenNot stickiedUnanswered
  • Forum posts: 1

Dec 24, 2015 8:59:32 AM via Website

Hello Guys,

We are developing one application which deal with AlarmManager class. We schedule alarm and app wake up at specific time and do some stuff.

It works fine when there is no restart or no switch on/off for mobile. but all alarm get cleared when we restart or turn off and on the phone this is because the AlarmManager class it self says.

Registered alarms are retained while the device is asleep (and can optionally wake the device up if they go off during that time), but will be cleared if it is turned off and rebooted.

To solve this issue we have implemented custom logic which is below one:

When restart or On and off occurs, at the boot complete event we fetching alarm from database and register/set them back so they can run as scheduled.

we already give below two permissions:


Now the problem is the custom wakeup works well with many phones Samsung, Lenova, Intex and some other phones but some how the process that set alarm back to AlarmManager after boot completion execute some time and some time it do not.

It having issue on ASUS and Samsung Galaxy S4, LG G3 and Doogee phone!

Here is the code we using :

java code set alarm

private void setAlarm(Calendar targetCal,int id)

      //uf.Show_Alert_Dialog(Screen_Add_Flight.this,"\n\n***\n"+ "Alarm is set@ " + targetCal.getTime() + "\n"+ "***\n",R.drawable.ic_launcher);

      Intent intent = new Intent(getBaseContext(), AlarmReceiver.class);
      //final int _id = (int) System.currentTimeMillis();
      final int _id = id;
      PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), _id, intent, PendingIntent.FLAG_ONE_SHOT);
      AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
          alarmManager.setExact(AlarmManager.RTC_WAKEUP, targetCal.getTimeInMillis(), pendingIntent);
          alarmManager.set(AlarmManager.RTC_WAKEUP, targetCal.getTimeInMillis(), pendingIntent);
      //alarmManager.setExact(AlarmManager.RTC_WAKEUP, targetCal.getTimeInMillis(), pendingIntent);


Receiver code

package com.passgrabber.checkinapp;

import java.util.Calendar;
import java.util.TimeZone;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.widget.Toast;

public class AlarmReceiver extends BroadcastReceiver
public void onReceive(Context context, Intent action)
Toast.makeText(context, "Alarm received!", Toast.LENGTH_LONG).show();

    Intent i = new Intent();
    i.setClassName("com.example.checkinapp", "com.example.checkinapp.Screen_Webview");


Android mainfest file

<receiver android:name=".AlarmReceiver" android:process=":remote" android:exported="true" android:enabled="true" android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

So any clue to fix this issue or is there something wrong with code ? Some thought or help will be really helpful!

Thanks in advance!!

— modified on Dec 24, 2015 9:04:43 AM

Deactivated Account
  • Forum posts: 271

Dec 24, 2015 3:13:33 PM via Website

I am still learning it so I think I might not be able to help you, but there are many other experts here, so be patient.

Looking for security app? Try Leo Privacy Guard 3.0.

Join Our Christmas Contest by visiting our Facebook page LEO Privacy Guard