Created
December 27, 2015 07:37
-
-
Save yishai-glide/a88342a58b2d21cc816e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void scheduleAutoCancel(@NonNull Context context) { | |
Intent intent = new Intent(context, MyReceiver.class); | |
AlarmManager manager = (AlarmManager)context.getSystemService(ALARM_SERVICE); | |
int requestCode = REQUEST_CODE; | |
PendingIntent action = PendingIntent.getBroadcast(context, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT); | |
long when = System.currentTimeMillis() + TIME_TO_WAUT_UNTIL_NOTIFICATION; | |
manager.set(AlarmManager.RTC, when, action); | |
} | |
public static class MyReceiver extends BroadcastReceiver { | |
@Override | |
public void onReceive(Context context, Intent intent) { | |
NotificationManager nm = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE); | |
NotificationCompat.Builder builder = new NotificationCompat.Builder(this) | |
.setContentIntent(getNotificationIntent()); | |
.setContentText("MESSAGE") | |
.setContentTitle("TITLE"); | |
nm.notify(builder.build(), getNotificationId()); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment