2024年3月14日发(作者:)

d有三种通知的方式

2. 状态区通知用于服务(service),吐司的用户交换接口更友好,下面简要说一下吐

司处理

//Toast通知可以改变通知位置.

vity(|, 0, 0);

//自定义吐司

Toast toast = new Toast(getApplicationContext());

vity(_VERTICAL, 0, 0);

ation(_LONG);

//布局文件

w(layout);

();

3.Android的状态栏通知(Notification)

通知用于在状态栏显示消息,消息到来时以图标方式表示,如下:

如果需要查看消息,可以拖动状态栏到屏幕下方即可查看消息。

发送消息的代码如下:

//获取通知管理器

NotificationManager nftm = (NotificationManager)

getSystemService(CATION_SERVICE);

int icon = _notify_chat;

long when = tTimeMillis();

//新建一个通知,指定其图标和标题

Notification notification = new Notification(icon, null, when);//第一个参数为图

标,第二个参数为标题,第三个为通知时间

ts = T_SOUND;//发出默认声音

Intent openintent = new Intent(this, );

PendingIntent contentIntent = ivity(this, 0, openintent,

0);//当点击消息时就会向系统发送openintent意图