通知的函数
@SuppressLint("WrongConstant")
void getNotification(){ NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
NotificationCompat.Builder builder = null;
String channelId = "com.message.notify";
String channelName = "notification";
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
NotificationChannel channel =new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_LOW);
manager.createNotificationChannel(channel);
builder = new NotificationCompat.Builder(this, channelId);
Log.e("xx","xxxxxx"+Build.VERSION.SDK_INT);
}else {
builder = new NotificationCompat.Builder(this);
builder.setChannelId(channelId);
}
builder.setContentTitle("消息通知标题")
.setContentText("消息通知内容")
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
.setPriority(NotificationCompat.PRIORITY_MAX);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.baidu.com"));
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
builder.setContentIntent(pendingIntent);
builder.setAutoCancel(true);
int notificationId = 1;
builder.setSound(Uri.fromFile(new File("/system/media/audio/ringtones/Luan.ogg")))
.setVibrate(new long[]{0, 1000, 1000, 1000})
.setLights(Color.GREEN, 1000, 1000)
.setDefaults(NotificationCompat.DEFAULT_ALL);
builder.setVisibility(Notification.VISIBILITY_PUBLIC);
builder.setFullScreenIntent(pendingIntent, true);
Notification notification = builder.build();
manager.notify(notificationId, notification);}