AndroidNotification使用方法详解

时间:2021-05-21

Android Notification使用详解

Notification

核心代码(链式调用):适用于Android 4.0以上(不兼容低版本)

Notification noti = new Notification.Builder(this).setContentTitle("标题名称").setContentText("标题里的内容").setSmallIcon(R.drawable.new_mail).setLargeIcon(BitmapFactory.decordResource(getResources(), R.drawable.ic_launcher)).build();NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);nm.notify(0, noti);

兼容版本

Notification notification = new Notification(R.drawable.ic_launcher, "xxxxxx", System.currentTimeMillis());//点击事件真正想执行的动作Intent intent = new Intent();intent.setAction(Intent.ACTION_DIAL);intent.setData(Uri.parse("tel:110"));PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);notification.setLatestEventInfo(this, "标题", "内容", contentIntent);NotificationManager nm = (NotificationManager) getSystemManager(NOTIFICATION_SERVICE);nm.notify(0, notification);

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章