Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Intent intent = new Intent(this, HomeActivity.class);
- intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- intent.putExtra(Constants.IS_FROM_NOTIFICATION, true);
- sendBroadcast(new Intent(Constants.REFRESH_STATUS));
- PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
- PendingIntent.FLAG_ONE_SHOT);
- NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
- NotificationCompat.Builder builder = null;
- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
- int importance = NotificationManager.IMPORTANCE_DEFAULT;
- NotificationChannel notificationChannel;
- // if (type.equals("1") || type.equals("2"))
- notificationChannel = new NotificationChannel("TripId", "Trip", importance);
- // else
- // notificationChannel = new NotificationChannel("ChatID", "Chat", importance);
- notificationManager.createNotificationChannel(notificationChannel);
- builder = new NotificationCompat.Builder(getApplicationContext(), notificationChannel.getId());
- builder.setPriority(NotificationManager.IMPORTANCE_HIGH);
- } else {
- builder = new NotificationCompat.Builder(getApplicationContext());
- builder.setPriority(Notification.PRIORITY_MAX);
- }
- Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
- builder = builder
- .setSmallIcon(R.mipmap.ic_notification_icon)
- // .setColor(ContextCompat.getColor(context, R.color.color))
- .setContentTitle(title)
- .setTicker(getString(R.string.app_name))
- .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
- .setContentText(message)
- .setDefaults(Notification.DEFAULT_ALL)
- .setAutoCancel(true)
- .setContentIntent(pendingIntent);
- notificationManager.notify((int) ((new Date().getTime() / 1000L) % Integer.MAX_VALUE), builder.build());
Add Comment
Please, Sign In to add comment