notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Intent intent=new Intent(this, MainActivity.class); PendingIntent pendingIntent=PendingIntent.getActivity(this,0,intent,0); Notification.Builder builder = new Notification.Builder(this); builder.setContentTitle("this is title"); builder.setTicker("this is ticker"); builder.setContentText("this is content"); builder.setSmallIcon(R.mipmap.ic_launcher); builder.setContentIntent(pendingIntent); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { notification = builder.build(); } else { notification = builder.getNotification(); } findViewById(R.id.btn_one).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { notificationManager.notify(0, notification); } }); findViewById(R.id.btn_two).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { notificationManager.cancel(0); } });
Notification 的应用
猜你喜欢
转载自blog.csdn.net/qq_35888847/article/details/80567383
今日推荐
周排行