I changed AlarmController.java in ApiDemo a bit, so I want the alarm not to go out when the phone is sleeping using AlarmManager.RTC.
Intent intent = new Intent(AlarmController.this, RepeatingAlarm.class);
PendingIntent sender = PendingIntent.getBroadcast(AlarmController.this,
0, intent, 0);
long firstTime = SystemClock.elapsedRealtime();
firstTime += 15*1000;
AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC,
firstTime, 15*1000, sender);
The receiver code is as follows:
public class RepeatingAlarm extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
Log.d("DEBUG", "In RepeatingAlarm.onReceive, intent=" + intent);
Toast.makeText(context, R.string.repeating_received, Toast.LENGTH_SHORT).show();
}
}
I launched a modified application, but still see a lot of log messages, as shown below, after the phone went offline (the screen was black):
D / DEBUG (1390): In RepeatingAlarm.onReceive, intent = Intent {flg = 0x4 cmp = com.example.android.apis / .app.RepeatingAlarm (has additional features)}
This means that the AlarmManager.RTC flag does not work. Can someone tell me why?
Thank.
source
share