android中创建通知栏Notification代码实例

android中创建通知栏Notification代码实例,第1张

概述/////第一步:获取NotificationManagerNotificationManagernm=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
///// 第一步:获取notificationmanager		notificationmanager nm = (notificationmanager) 				getSystemService(Context.NOTIFICATION_SERVICE);		///// 第二步:定义Notification		Intent intent = new Intent(this,OtherActivity.class);		//PendingIntent是待执行的Intent		PendingIntent pi = PendingIntent.getActivity(this,intent,PendingIntent.FLAG_CANCEL_CURRENT);		Notification notification = new Notification.Builder(this)				.setContentTitle("Title")				.setContentText("text")				.setSmallicon(R.drawable.ic_launcher).setContentIntent(pi)				.build();		notification.flags = Notification.FLAG_NO_CLEAR;				/////第三步:启动通知栏,第一个参数是一个通知的唯一标识		nm.notify(0,notification);				//关闭通知		//nm.cancel(0);

总结

以上是内存溢出为你收集整理的android中创建通知栏Notification代码实例全部内容,希望文章能够帮你解决android中创建通知栏Notification代码实例所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1142334.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-31
下一篇2022-05-31

发表评论

登录后才能评论

评论列表(0条)

    保存