Android通知大图标,有没有办法删除右下角的小图标?
我有一个显示大图标的通知 有没有办法从该视图中删除蜂巢和以上设备的较小图标 显然,仍然保留顶部状态栏的小图标Android通知大图标,有没有办法删除右下角的小图标?,android,notifications,status,Android,Notifications,Status,我有一个显示大图标的通知 有没有办法从该视图中删除蜂巢和以上设备的较小图标 显然,仍然保留顶部状态栏的小图标 NotificationCompat.Builder builder = new NotificationCompat.Builder(context) // Set required fields, including the small icon, the // notification title, and text.
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
// Set required fields, including the small icon, the
// notification title, and text.
.setSmallIcon(R.drawable.ic_notify_status_new)
.setContentTitle(title)
.setContentText(text)
// All fields below this line are optional.
// Use a default priority (recognized on devices running Android
// 4.1 or later)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
// Provide a large icon, shown with the notification in the
// notification drawer on devices running Android 3.0 or later.
.setLargeIcon(picture)
.setContentIntent(
PendingIntent.getActivity(
context,
0,
notiIntent,
PendingIntent.FLAG_UPDATE_CURRENT)
);
builder = getNotiSettings(builder);
notify(context, builder.build());
只有一种方法:
使用自定义布局
您的问题可能与生成通知后添加此代码的问题重复
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
int smallIconViewId = getResources().getIdentifier("right_icon", "id", android.R.class.getPackage().getName());
if (smallIconViewId != 0) {
if (notif.contentIntent != null)
notif.contentView.setViewVisibility(smallIconViewId, View.INVISIBLE);
if (notif.headsUpContentView != null)
notif.headsUpContentView.setViewVisibility(smallIconViewId, View.INVISIBLE);
if (notif.bigContentView != null)
notif.bigContentView.setViewVisibility(smallIconViewId, View.INVISIBLE);
}
}
如果“notif”是生成的通知,则仅使用setSmallIcon作为图标。如果没有指定第二个,它也将用于largeIcon(只要确保它足够大,可以同时容纳这两个) 确保它在lolipop前、lolipop及以上的场合看起来不错。例如,在这里我只为lolipop之前的设备设置应用程序图标,lolipop和上面的设备得到不同的smallIcon和与smallIcon相同的largeIcon
int currentApiVersion = android.os.Build.VERSION.SDK_INT;
if (currentApiVersion >= Build.VERSION_CODES.LOLLIPOP) {
notificationBuilder
.setSmallIcon(smallIcon)
.setLargeIcon(appIconDrawable)
} else {
notificationBuilder.setSmallIcon(appIconDrawable);
}
大视图是Android 4.1中引入的,在旧设备上不受支持。
您找到解决此问题的方法了吗?非常感谢,它对我有效,我不检查SDK INT,只是获取smallIconViewId并将视图设置为不可见,在低于21的api上效果良好。您的意思是如果(notif.contentView!=null)不是notif.contentIntent?不,我没有,这是在单击扩展状态条目时执行的意图。请将if(notif.contentIntent!=null)
更改为if(notif.contentView!=null)
通知.contentView.setImageViewResource()
有效,但contentView
不推荐使用。但是使用NotificationCompat.Builder.getContentView().setImageViewResource()
(在NotificationCompat.build()
或NotificationManager.notify()
之前或之后)不起作用是的,它是重复的。不,还有其他方法:不要使用“setLargeIcon”。