gpt4 book ai didi

android - Android O 中的通知标记

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:36:12 24 4
gpt4 key购买 nike

我正在使用带有 Android Oreo SDK 的 Google Nexus 5x 进行测试。我无法在主屏幕的应用程序图标中找到通知徽章,即使我收到了来自应用程序的通知,应用程序快捷方式也没有显示数字。以下是代码 fragment :

 final NotificationManager mNotific=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);

CharSequence name="Ragav";
String desc="this is notific";
int imp=NotificationManager.IMPORTANCE_HIGH;
final String ChannelID="my_channel_01";

NotificationChannel mChannel=new NotificationChannel(ChannelID,name,imp);
mChannel.setDescription(desc);
mChannel.setLightColor(Color.CYAN);
mChannel.canShowBadge();
mChannel.setShowBadge(true);

mNotific.createNotificationChannel(mChannel);

final int ncode=1;

String Body="This is testing notific";
final Notification n= new Notification.Builder(getApplicationContext(),ChannelID)
.setContentTitle(getPackageName())
.setContentText(Body)
.setNumber(5)
.setBadgeIconType(R.mipmap.ic_launcher_round)
.setSmallIcon(R.mipmap.ic_launcher_round)
.setAutoCancel(true).build();

for(int i=0;i<25;i++) {
Thread.sleep(1000);
mNotific.notify(ncode, n);
}

最佳答案

您无法自定义应用启动器图标上显示的通知标记(点)的外观。但是,当您长按应用程序的启动器图标时,您可以自定义长按菜单的某些元素,例如,您尝试的 .setNumber(5) 将显示在那里。

请参阅此处以获得更多见解:Notification BadgesAdjusting Notification Badges .

引用.setBadgeIconType(R.mipmap.ic_launcher_round),我建议您阅读this .


** 编辑 ** (问题被误解)

我已经在 Nexus 5X 模拟器上测试了您的代码(没有 for 循环,仅调用 mNotific.notify(ncode, n); 一次),它可以运行 100显示通知点的百分比。这不是代码相关的问题。

Nexus 5X 物理设备的 native 启动器应用程序 (Google Now) 不支持通知点,即使您可以在设备的 Oreo 设置中“打开”通知点。引用thisthis关联。要在 Nexus 5X 物理设备上启用通知点,您必须安装自定义 Pixel Launcher 应用程序,例如 Rootless Pixel Launcher .

关于android - Android O 中的通知标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46000499/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com