自从notification.setLatestEventInfo()不再让用之后,百度后发现了新的解决办法,直接贴代码
NotificationManager manager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
//新建一个Notification管理器;
//API level 11
Notification.Builder builder = new Notification.Builder(this);//新建Notification.Builder对象
PendingIntent intent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);
//PendingIntent点击通知后所跳转的页面
builder.setContentTitle("Bmob Test");
builder.setContentText("message");
builder.setSmallIcon(R.mipmap.ic_launcher);
builder.setContentIntent(intent);//执行intent
Notification notification = builder.getNotification();//将builder对象转换为普通的notification
notification.flags |= Notification.FLAG_AUTO_CANCEL;//点击通知后通知消失
manager.notify(1,notification);//运行notification