我试图在通话结束后显示来自电话状态接收器的气泡通知,并将其显示为普通通知。但是当我从按钮单击事件发送通知时,它会显示气泡通知。
这是清单文件气泡活动
<activity android:name=".BubbleActivity"
android:label="@string/to_do_bubble"
android:allowEmbedded="true"
android:documentLaunchMode="always"
android:resizeableActivity="true">
用于在电话状态广播接收器中显示气泡通知的片段
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());
}
}
此代码在通话结束后显示普通通知而不是气泡通知。
相同的代码(需要从活动运行进行某些更改)我尝试单击按钮,它按预期显示气泡通知。我在模拟器上运行API level 29
and compileSDKVersion 29
andtargetSDKVersion 29