Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void showNotification(Context context, String title, String body, Intent intent) {
- NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
- int notificationId = 1;
- String channelId = "channel-01";
- String channelName = "Channel Name";
- int importance = NotificationManager.IMPORTANCE_HIGH;
- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
- NotificationChannel mChannel = new NotificationChannel(
- channelId, channelName, importance);
- notificationManager.createNotificationChannel(mChannel);
- }
- NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, channelId)
- .setSmallIcon(R.drawable.bawasluicon)
- .setContentTitle(title)
- .setContentText(body);
- TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
- stackBuilder.addNextIntent(intent);
- PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(
- 0,
- PendingIntent.FLAG_UPDATE_CURRENT
- );
- mBuilder.setContentIntent(resultPendingIntent);
- notificationManager.notify(notificationId, mBuilder.build());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement