在android8之后,使用Notification需要先创建渠道
伪代码如下
NotificationManager notificationManager=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE) ;
Intent intent=new Intent(this,Second.class);
Context context=this;
PendingIntent pendingIntent=PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT);
CharSequence name;
Button v1 = (Button) v;
NotificationChannel notificationChannel=new NotificationChannel("1", "name", 5);
notificationManager.createNotificationChannel(notificationChannel);
NotificationCompat.Builder mb=new NotificationCompat.Builder(this,"1");
mb.setContentTitle("曾鑫磊")
.setContentText("如果没住在你心里,都是客死他乡")
.setSmallIcon(R.mipmap.mm)
.setTicker("收到一条消息").setWhen(System.currentTimeMillis())
.setContentIntent(pendingIntent);
notificationManager.notify(1,mb.build());
手机扫一扫
移动阅读更方便
你可能感兴趣的文章