Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing Snooze in Android Notifications

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?

like image 865
yydl Avatar asked Apr 21 '11 15:04

yydl


People also ask

What does it mean to snooze notifications?

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 .

What is snooze on Android phone?

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.


1 Answers

  1. 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;
            }
    });       
    
  2. 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);
    
  3. Call the alarm now.

like image 176
sophia Avatar answered Sep 19 '22 20:09

sophia