Skip to content

Instantly share code, notes, and snippets.

@diewland
Created September 18, 2017 03:30
Show Gist options
  • Save diewland/7705c9150ff44d129924131f71722fd7 to your computer and use it in GitHub Desktop.
Save diewland/7705c9150ff44d129924131f71722fd7 to your computer and use it in GitHub Desktop.
Send android notification
// https://alvinalexander.com/android/how-to-create-android-notifications-notificationmanager-examples
public void showNotification(String s){
PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);
Notification notification = new NotificationCompat.Builder(this)
.setTicker("Demo")
.setSmallIcon(android.R.drawable.ic_menu_help)
.setContentTitle("Demo Notification")
.setContentText(s)
.setContentIntent(pi)
.setAutoCancel(true)
.build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, notification);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment