0

Expected Behavior: Open URL when notification is clicked.

Actual Behavior: Notification bar closes like nothing happened. Responses:

   Real Device: START u0 {act=https://www.google.com flg=0x14000000 pkg=com.geoenglish (has extras)} from uid 10193 on display 0

   Emulator: Notification pending intent canceled

I have tried using different flags but nothing worked

NotificationCompat.Builder builder = new NotificationCompat.Builder(MyService.this, "01")
                .setSmallIcon(R.drawable.ic_stat_name)
                .setBadgeIconType(NotificationCompat.BADGE_ICON_SMALL)
                .setPriority(NotificationCompat.PRIORITY_MAX)
                .setAutoCancel(true);

Intent notificationIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(remoteMessage.getNotification().getClickAction()));
            notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
            PendingIntent pending = PendingIntent.getActivity(MyService.this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

            if (ToggleNotification._showNotification == true) {
                builder.setContentText(remoteMessage.getNotification().getBody());
                builder.setContentTitle(remoteMessage.getNotification().getTitle());
                builder.setLargeIcon(image);
                builder.setContentIntent(pending);
                try {
                    URL url = new URL(remoteMessage.getNotification().getImageUrl().toString());
                    image = BitmapFactory.decodeStream(url.openConnection().getInputStream());
                } catch (IOException e) {
                    System.out.println(e);
                }

                notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                    notificationManager.createNotificationChannel(channel);
                }

                notificationManager.notify(121, builder.build());
            }
S.Ayesh
  • 1
  • 2
  • Notification intent instantiation code is missing. Please add it. The issue is likely in the flags and params you use for the notification intent – alaeri Oct 25 '19 at 10:30
  • @alaeri I have added the remaining code – S.Ayesh Oct 25 '19 at 12:03
  • Have you checked this link already? https://stackoverflow.com/questions/6232288/opening-a-browser-link-through-notification-isnt-working . I'm not sure what is causing your issue as your code seems similar. have you tried setting all flags to 0? – alaeri Oct 25 '19 at 12:41
  • Yes, I have tried it already – S.Ayesh Oct 25 '19 at 13:39

0 Answers0