您的位置:首页 > 移动开发 > Android开发

Android通知代码

2016-05-13 14:45 381 查看
public void notice() {
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);

Context context = getApplicationContext();
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,notificationIntent, 0);
Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Notification notification = new NotificationCompat// 注意:4.4.2版本使用的方法
.Builder(context) 						//上下文
.setAutoCancel(true) 					//自动取消
.setContentTitle("title") 				//标题
.setContentText("describe") 			//描述
.setContentIntent(contentIntent)		//通知动作
.setSmallIcon(R.drawable.ic_launcher)	//图标
.setWhen(System.currentTimeMillis())	//时间
.setSound(alert)						//声音
.build();								//建立通知

mNotificationManager.notify(1, notification);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: