Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void showNotifications(String title, String msg, String deepLink){
- msg = msg.replace("<br/>", "n");
- Spanned htmlText = Html.fromHtml(msg);
- RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_push);
- contentView.setImageViewResource(R.id.image, R.mipmap.ic_launcher_foreground);
- contentView.setTextViewText(R.id.title, title);
- contentView.setTextViewText(R.id.text, htmlText);
- Intent intent ;
- if (deepLink!=null)
- intent = new Intent(deepLink);
- else
- intent = new Intent(this, MainActivity.class);
- //get desired location from deep link
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
- intent.putExtra("title", title);
- intent.putExtra("message", msg);
- PendingIntent pendingIntent = PendingIntent.getActivity(this, REQUEST_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT);
- Random rand = new Random();
- int notificationID = rand.nextInt(50000);
- Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
- NotificationCompat.Builder notification = new NotificationCompat.Builder(getApplicationContext(), NOTIF_CHANNEL_ID)
- .setContent(contentView)
- .setContentIntent(pendingIntent)
- .setSound(defaultSoundUri)
- .setSmallIcon(R.drawable.status_bar_icon)
- .setAutoCancel(true)
- .setChannelId(NOTIF_CHANNEL_ID);
- NotificationChannel channel = new NotificationChannel(NOTIF_CHANNEL_ID, NOTIF_CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);
- channel.enableLights(true);
- channel.setShowBadge(true);
- channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
- channel.enableVibration(true);
- NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
- manager.createNotificationChannel(channel);
- // manager.notify(notificationID, notification.build());
- manager.notify(NOTIF_CHANNEL_ID, notificationID, notification.build());
- }
- else
- {
- Notification notification = new NotificationCompat.Builder(this)
- .setContent(contentView)
- .setContentIntent(pendingIntent)
- .setSmallIcon(R.drawable.status_bar_icon)
- .setSound(defaultSoundUri)
- .setAutoCancel(true)
- .setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 })
- .build();
- NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
- manager.notify(notificationID, notification);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement