Created
September 18, 2017 03:30
-
-
Save diewland/7705c9150ff44d129924131f71722fd7 to your computer and use it in GitHub Desktop.
Send 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
// 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