PHP
·
发表于 5年以前
·
阅读量:8391
2.编写如下代码
//Note 为 Activity的类名
Intent intent=new Intent(this,Note.class);
PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0); //延迟执行
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notification=new NotificationCompat.Builder(this)
.setContentTitle("通知标题")
.setContentText("通知正文")
.setWhen(System.currentTimeMillis()) //何时发出通知
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
.setContentIntent(pi)
.setDefaults(NotificationCompat.DEFAULT_ALL)
// .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(BitmapFactory.decodeResource(getResources(), R.drawable.big_image)))
.setPriority(NotificationCompat.PRIORITY_MAX)
.build();
manager.notify(1, notification); //参数(通知id ,Notification的实例对象)
3.点击通知后会跳转到Note的Activity