相信多数人都知道安卓上的通知,这原本是安卓系统的一大特点,早期iOS和wp还没有。
一、创建通知的步骤:
1.创建NotificationManager
2.创建Notification
3.调用NotificationManager的方法notify()产生通知
代码如下:
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification.Builder(this)
.setContentTitle("This is content title")
.setContentText("This is ticker text")
.setSmallIcon(R.mipmap.ic_launcher)
.build();
manager.notify(1, notification);
二、通知的其它属性
1.点击通知框弹出窗口
2.弹出窗口后关闭通知
例子完整代码:
MainActivity:
package com.example.administrator.notification;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.C