-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[flutter_local_notifications] Add support to pass bubble activity + intent to notification #2484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
ddfade4
7e3ae5a
a502fb4
3e4345e
2ed87e4
1d20109
aa7b3ad
0cdda35
866c9b7
fe814cc
f5e8911
0891e4e
5badecb
5668a22
78a9fe5
93f9069
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -443,6 +443,50 @@ protected static Notification createNotification( | |
| setProgress(notificationDetails, builder); | ||
| setCategory(notificationDetails, builder); | ||
| setTimeoutAfter(notificationDetails, builder); | ||
|
|
||
| if (notificationDetails.bubbleActivity != null) { | ||
| try { | ||
| Class cls = Class.forName(notificationDetails.bubbleActivity); | ||
| Intent bubbleIntent = new Intent(context, cls); | ||
| bubbleIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | ||
|
|
||
| if (notificationDetails.bubbleExtra != null) { | ||
| final Bundle extra = new Bundle(); | ||
| extra.putString("bubbleExtra", notificationDetails.bubbleExtra); | ||
| bubbleIntent.putExtras(extra); | ||
| } | ||
|
|
||
| int actionFlags = PendingIntent.FLAG_MUTABLE | PendingIntent.FLAG_UPDATE_CURRENT; | ||
| PendingIntent pendingBubbleIntent = | ||
| PendingIntent.getActivity(context, notificationDetails.id, bubbleIntent, actionFlags); | ||
|
|
||
| IconCompat icon = | ||
| IconCompat.createWithResource( | ||
| context, getDrawableResourceId(context, notificationDetails.icon)); | ||
|
|
||
| if (!StringUtils.isNullOrEmpty(notificationDetails.shortcutId)) { | ||
|
|
||
| var bubbleBuilder = | ||
| new androidx.core.app.NotificationCompat.BubbleMetadata.Builder() | ||
| .setIntent(pendingBubbleIntent) | ||
| .setIcon(icon); | ||
|
|
||
| if (notificationDetails.bubbleDesiredHeight != null) { | ||
| bubbleBuilder.setDesiredHeight(notificationDetails.bubbleDesiredHeight); | ||
| } | ||
|
|
||
| if (notificationDetails.bubbleAutoExpand != null) { | ||
| bubbleBuilder.setAutoExpandBubble(notificationDetails.bubbleAutoExpand); | ||
| } | ||
|
|
||
| var bubbleData = bubbleBuilder.build(); | ||
| builder.setBubbleMetadata(bubbleData); | ||
| } | ||
| } catch (ClassNotFoundException e) { | ||
| e.printStackTrace(); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a reason for swallowing the exception? can this be surfaced as an exception on the Flutter with appropriate details for users of the plugin to handle?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure the best way to do this, I would appreciate some guidance here
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When catching the |
||
| } | ||
| } | ||
|
|
||
| Notification notification = builder.build(); | ||
| if (notificationDetails.additionalFlags != null | ||
| && notificationDetails.additionalFlags.length > 0) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /// Defines metadata to be set for the notification's chat bubble | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a general comment on all the API docs
|
||
| /// See: https://developer.android.com/develop/ui/views/notifications/bubbles | ||
| class BubbleMetadata { | ||
| /// Encapsulates the information needed to display a notification as a bubble. | ||
| /// A bubble is used to display app content in a floating window over the | ||
| /// existing foreground activity. A bubble has a collapsed state represented | ||
| /// by an icon and an expanded state that displays an activity. | ||
| /// - https://developer.android.com/reference/android/app/Notification.BubbleMetadata | ||
| BubbleMetadata( | ||
| this.activity, { | ||
| this.extra, | ||
| this.autoExpand, | ||
| this.desiredHeight, | ||
| }); | ||
|
|
||
| /// Define which activity should be started by the bubble | ||
| /// This activity needs to be declared in your android Manfiest.xml | ||
| /// As well as in the native code | ||
| final String activity; | ||
|
|
||
| /// Pass additional data to the bubble activities intent | ||
| final String? extra; | ||
|
|
||
| /// the ideal height, in DPs, for the floating window created by this activity | ||
| final int? desiredHeight; | ||
|
|
||
| /// whether this bubble should auto expand when it is posted. | ||
| final bool? autoExpand; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I missed this before but can you refactor out all the changes to a separate method