Created
May 16, 2019 06:51
-
-
Save saddahussain/e3dd5b08f0fb1a229f654de099561625 to your computer and use it in GitHub Desktop.
This file contains 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
private void createNotification(String title, String message) { | |
int num = (int) System.currentTimeMillis(); | |
Intent resultIntent = new Intent(PusherService.this, MainActivity.class); | |
resultIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); | |
resultIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); | |
PendingIntent resultPendingIntent = | |
PendingIntent.getActivity(this, num, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); | |
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this); | |
mBuilder.setContentTitle(title) | |
.setContentText(message) | |
.setAutoCancel(true) | |
.setSmallIcon(R.mipmap.ic_launcher) | |
.setSound(Settings.System.DEFAULT_NOTIFICATION_URI) | |
.setContentIntent(resultPendingIntent); | |
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); | |
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { | |
int importance = NotificationManager.IMPORTANCE_HIGH; | |
NotificationChannel notificationChannel = new NotificationChannel("1", "Notifications", importance); | |
notificationChannel.enableLights(true); | |
notificationChannel.setLightColor(Color.RED); | |
notificationChannel.enableVibration(true); | |
notificationChannel.setVibrationPattern(new long[]{100L, 200L, 300L, 400L, 500L, 400L, 300L, 200L, 400L}); | |
mBuilder.setChannelId("1"); | |
mNotificationManager.createNotificationChannel(notificationChannel); | |
} | |
mNotificationManager.notify(num, mBuilder.build()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment