What's the best way to implement snooze functionality in an Android notification. (i.e. I notify user of X [for arguments sake lets use the example of a text message], and he doesn't want to be bothered by it for now, yet at the same time he wants to make sure he doesn't forget. So he does want it to play the noise again, but at e.g. 5 minutes from now)
I saw the way the android alarm clock does it, but to me it seems messy (and usually not good) to popup a floating intent while the user might be doing something important.
On the other hand, it doesn't seem possible to put buttons inside the notification area. Or am I wrong?
What would you suggest?
Postpone emails and temporarily remove them from your inbox until you need them. Your email will come back to the top of your inbox when you want it to, whether that's tomorrow, next week, or this evening. You can find your snoozed items under Snoozed in the Menu .
Snooze: To delay an alarm for 10 minutes, on your lock screen, swipe left. Stop: To stop an alarm, on your lock screen, swipe right.
Add a snooze button:
Button snooze = (Button) findViewById(R.id.snooze);
snooze.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View arg0, MotionEvent arg1) {
mMediaPlayer.stop();
finish();
return true;
}
});
Then before where you call the alarm, update the time
Intent intent = new Intent(this, this.getClass());
PendingIntent pendingIntent =
PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
long currentTimeMillis = System.currentTimeMillis();
long nextUpdateTimeMillis = currentTimeMillis + 5 * DateUtils.MINUTE_IN_MILLIS;
Time nextUpdateTime = new Time();
nextUpdateTime.set(nextUpdateTimeMillis);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC, nextUpdateTimeMillis, pendingIntent);
Call the alarm now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With