Android7.0系統(tǒng)對(duì)通知欄進(jìn)行了升級(jí)漆弄,在同一個(gè)應(yīng)用程序下,如果超過(guò)4條通知造锅,會(huì)自動(dòng)把通知進(jìn)行分組撼唾。
211515034801_.pic.jpg
201515034801_.pic.jpg
那我們可以把分組分成兩部分組頭和組員:
組頭是開(kāi)心就好^,組員就是某一條的通知哥蔚。
點(diǎn)擊下拉列表顯示出全部組員信息倒谷。點(diǎn)擊某一條組員根據(jù)ContentIntent進(jìn)行跳轉(zhuǎn)。
但是在這里又一個(gè)問(wèn)題糙箍,就是點(diǎn)擊組頭的時(shí)候渤愁,無(wú)法控制他的跳轉(zhuǎn)。
這就導(dǎo)致測(cè)試人員給我提bug了深夯。
那有問(wèn)題了就該去解決啊抖格。
怎么解決呢
- 取消分組
設(shè)置這兩個(gè)方法,就會(huì)取消分組每個(gè)組員都單個(gè)顯示:
setGroupSummary(false)
setGroup("group")
完整代碼
int timeMillis = (int) System.currentTimeMillis();
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentTitle("標(biāo)題")
.setSmallIcon(R.mipmap.ic_launcher)//圖標(biāo)必須設(shè)置,如果不設(shè)置會(huì)報(bào)錯(cuò)
.setContentText("內(nèi)容")
.setAutoCancel(true)
.setTicker("動(dòng)畫(huà)")
.setWhen(timeMillis)
.setGroupSummary(false)
.setGroup("group")
.setContentIntent(getContentIntent(timeMillis))
//等價(jià)于setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE);
//.setDefaults(Notification.DEFAULT_ALL)
//.setSound(Uri.parse("file:///sdcard/dance.mp3"))
//.setLights(0xff00eeff, 500, 200)
.setVibrate(new long[]{0, 300, 500, 700})//實(shí)現(xiàn)效果:延遲0ms,然后振動(dòng)300ms他挎,在延遲500ms筝尾,接著在振動(dòng)700ms。
.setNumber(4);
Notification build = builder.build();
//設(shè)置三色燈提醒
// build.flags = Notification.FLAG_SHOW_LIGHTS;
// build.ledARGB = 0xff00eeff;
// build.ledOnMS = 500;
// build.ledOffMS = 200;
nm.notify(timeMillis, build);
那這么設(shè)置會(huì)是什么樣的效果呢办桨?
221515036977_.pic.jpg
- 自己設(shè)置分組筹淫,但是有問(wèn)題,所以項(xiàng)目中沒(méi)有使用呢撞,就是點(diǎn)擊組頭沒(méi)有反應(yīng)损姜。哪位大神如果知道怎么做請(qǐng)給我留言。
int timeMillis = (int) System.currentTimeMillis();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
final NotificationCompat.Builder builder2 = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setStyle(new NotificationCompat.BigTextStyle())
.setGroup(NOTIFICATION_GROUP)
.setAutoCancel(true)
.setGroupSummary(true);
final Notification notification = builder2.build();
nm.notify(1, notification);
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder = builder.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("大大標(biāo)題")
.setContentText("小小內(nèi)容")
.setGroup(NOTIFICATION_GROUP)
.setAutoCancel(true)
.setGroupSummary(false)
//.setGroup("group")
.setContentIntent(getContentIntent(timeMillis));
nm.notify(timeMillis, builder.build());
在我的項(xiàng)目中殊霞,只有android7.0版本以下都是正常的摧阅,所以我對(duì)版本進(jìn)行了控制。
241515038547_.pic.jpg
231515038546_.pic.jpg
還是點(diǎn)擊下拉出現(xiàn)組員條目信息绷蹲。
但是有個(gè)問(wèn)題棒卷,就是點(diǎn)擊組頭沒(méi)反應(yīng)。
我想自己控制邏輯祝钢。比规。。拦英。蜒什。