不用做配置的通知
//sdk版本
minSdkVersion 16 // 支持Notification.Builder 15以下支持NotificationCompat.Builder
targetSdkVersion 22
private void Notification(String name) {
Intent intent = new Intent(getActivity(), InforActivity.class);
intent.putExtra("information",name);//用于點(diǎn)擊通知跳轉(zhuǎn)到另一個(gè)頁面時(shí) 通過getIntent獲取通知內(nèi)容
PendingIntent activity = PendingIntent.getActivity(getActivity(), 100, intent, PendingIntent.FLAG_CANCEL_CURRENT);
NotificationManager manger = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
Notification build = new Notification.Builder(getActivity())
.setContentTitle(name)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentIntent(activity)
.build();
manger.notify(1,build);
}
有時(shí)候不想設(shè)置通知的圖標(biāo) 就會導(dǎo)致通知不彈出留瞳,所以必須設(shè)置圖標(biāo)