gpt4 book ai didi

Android 通知不显示标题图像 JPG 或 PNG 格式

转载 作者:太空狗 更新时间:2023-10-29 14:48:37 27 4
gpt4 key购买 nike

我正在尝试在通知栏中显示图像。但是当我设置 JPG 格式的图像时,我的应用程序因 android 停止进程而关闭。当我设置 PNG 图标时,图标不显示在那里。我将两种类型的图标都调整为 32dp,并尝试调整为 24dp。这是我的代码和截图——

  public void shownotification(View view){

Intent intent = new Intent();
PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this,0,intent,0);
Notification notification = new Notification.Builder(MainActivity.this)
.setTicker("Tittle")
.setContentTitle("Content Tittle")
.setContentText("All details of Content")
.setSmallIcon(R.drawable.cdc)
.setContentIntent(pendingIntent).getNotification();
notification.flags = Notification.FLAG_AUTO_CANCEL;
NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0,notification);
}

enter image description here

最佳答案

Cause for the issue is for 5.0 Lollipop and above version "Notification icons must be entirely white".

请引用以下内容创建您的通知图标https://design.google.com/icons/

并更改您的代码以使用以下代码设置图标

    public void shownotification(View view){    
Intent intent = new Intent();
PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this,0,intent,0);
Notification notification = new Notification.Builder(MainActivity.this)
.setTicker("Tittle")
.setContentTitle("Content Tittle")
.setContentText("All details of Content")
.setContentIntent(pendingIntent).getNotification();
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
notification.setSmallIcon(R.drawable.cdc_icon_transperent);
} else {
notification.setSmallIcon(R.drawable.cdc);
}

notification.flags = Notification.FLAG_AUTO_CANCEL;
NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0,notification);
}

其中 R.drawable.cdc_icon_transperent 是新的白色图标

关于Android 通知不显示标题图像 JPG 或 PNG 格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37260011/

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