Android Notification使用方法详解
Android Notification使用详解
Notification
核心代码(链式调用):适用于Android4.0以上(不兼容低版本)
Notificationnoti=newNotification.Builder(this) .setContentTitle("标题名称") .setContentText("标题里的内容") .setSmallIcon(R.drawable.new_mail) .setLargeIcon(BitmapFactory.decordResource(getResources(),R.drawable.ic_launcher)) .build(); NotificationManagernm=(NotificationManager)getSystemService(NOTIFICATION_SERVICE); nm.notify(0,noti);
兼容版本
Notificationnotification=newNotification(R.drawable.ic_launcher,"xxxxxx",System.currentTimeMillis()); //点击事件真正想执行的动作 Intentintent=newIntent(); intent.setAction(Intent.ACTION_DIAL); intent.setData(Uri.parse("tel:110")); PendingIntentcontentIntent=PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(this,"标题","内容",contentIntent); NotificationManagernm=(NotificationManager)getSystemManager(NOTIFICATION_SERVICE); nm.notify(0,notification);
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!