private void SendMessage() {
manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
String id= "123";
CharSequence name= "冒险了";
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(id, name, NotificationManager.IMPORTANCE_DEFAULT);
manager.createNotificationChannel(channel);
}
Intent intent = new Intent(HomeActivity.this,WebViewActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 100, intent, PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification = new NotificationCompat.Builder(this, id)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("提醒一下")
.setContentText("很危险的")
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.build();
manager.notify(1,notification);
}
把此方法代码放到你需要的功能下点击即可,当然,消息通知内容自己改成需要的就好.
网友评论