2

I'm trying to show a bubble notification from a phone state receiver after call ends and its displaying as an ordinary notification. But it displays a bubble notification when I send notification from a button click event.

Here is manifest file bubble activity

<activity android:name=".BubbleActivity"
            android:label="@string/to_do_bubble"
            android:allowEmbedded="true"
            android:documentLaunchMode="always"
            android:resizeableActivity="true">

Snippet for showing bubble notification in phone state broadcast receiver

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q){

                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                                
                                CharSequence name = "nameHere";
                                String description = "DescriptionHere";
                                int importance = NotificationManager.IMPORTANCE_HIGH;
                                NotificationChannel channel = new NotificationChannel("1001", name, importance);
                                channel.setDescription(description);
                                channel.setAllowBubbles(true);
                                // Register the channel with the system; you can't change the importance
                                // or other notification behaviors after this
                                NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
                                notificationManager.createNotificationChannel(channel);
                            }

                            // Create bubble intent
                            Intent target = new Intent(context, PopUpBubbleActivity.class);
                            PendingIntent bubbleIntent =
                                    PendingIntent.getActivity(context, 0, target, 0 /* flags */);


                            // Create bubble metadata
                            Notification.BubbleMetadata bubbleData =
                                    new Notification.BubbleMetadata.Builder()
                                            .setDesiredHeight(600)
                                            .setIcon(Icon.createWithResource(context, R.mipmap.ic_launcher))
                                            .setIntent(bubbleIntent)
                                            .setAutoExpandBubble(true)
                                            .setSuppressNotification(true)
                                            .build();

                            Person chatBot = new Person.Builder()
                                    .setBot(true)
                                    .setName("BubbleBot")
                                    .setImportant(true)
                                    .build();

                            Notification.Builder builder =
                                    new Notification.Builder(context, "1001")
                                            .setContentTitle("New message")
                                            .setContentText("Click to open new message")
                                            .setContentIntent(bubbleIntent)
                                            .setSmallIcon(R.mipmap.ic_launcher)
                                            .setBubbleMetadata(bubbleData)
                                            .setAutoCancel(true)
                                            .addPerson(chatBot);

                            NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
                            notificationManager.notify(1001, builder.build());

                           
                        }


                    }

This code is displaying ordinary notification instead of bubble notification after call end. This same code(with certain changes required to run from activity) I tried on button click and it's displaying a bubble notification as expected. I'm running on emulator with API level 29 and compileSDKVersion 29 and targetSDKVersion 29

Harsha pulikollu
  • 2,386
  • 15
  • 28

0 Answers0