Last active
August 29, 2015 14:26
-
-
Save mortenjust/018a81ee7917a6f516c6 to your computer and use it in GitHub Desktop.
Android Notification
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 void sendNotification(){ | |
// set up notification | |
int NOTIFICATION_ID = 0; | |
PendingIntent activityPendingIntent = getActivityPendingIntent(); | |
Notification n = new NotificationCompat.Builder(this) | |
.setContentTitle("You won!") | |
.setContentText("A trip to the neighbors") | |
.setSmallIcon(R.drawable.abc_btn_radio_material) | |
.setContentIntent(activityPendingIntent) | |
.build(); | |
NotificationManagerCompat nm = NotificationManagerCompat.from(this); | |
nm.notify(NOTIFICATION_ID, n); | |
} | |
public PendingIntent getActivityPendingIntent(){ | |
Intent activityIntent = new Intent(this, MainActivity.class); | |
activityIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); | |
return PendingIntent.getActivity(this, 0, activityIntent, PendingIntent.FLAG_UPDATE_CURRENT); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment