NotificationCompat.Builder builder = new NotificationCompat.Builder(context, Define.NOTIFICATION_CHANNELID);
builder.setContentTitle("제목")
.setContentText("내용")
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher))
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setSound(Settings.System.DEFAULT_NOTIFICATION_URI)
.setVibrate(new long[] { 0, 1000 });
NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
if (null != notificationManager) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel mChannel = new NotificationChannel(Define.NOTIFICATION_CHANNELID, "채널이름",importance);
mChannel.enableVibration(true);
mChannel.setVibrationPattern(new long[] { 0, 1000 });
mChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
notificationManager.createNotificationChannel(mChannel);
}
notificationManager.notify(Define.NOTIFY_ID, builder.build());
}
builder.setContentTitle("제목")
.setContentText("내용")
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher))
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setSound(Settings.System.DEFAULT_NOTIFICATION_URI)
.setVibrate(new long[] { 0, 1000 });
NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
if (null != notificationManager) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel mChannel = new NotificationChannel(Define.NOTIFICATION_CHANNELID, "채널이름",importance);
mChannel.enableVibration(true);
mChannel.setVibrationPattern(new long[] { 0, 1000 });
mChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
notificationManager.createNotificationChannel(mChannel);
}
notificationManager.notify(Define.NOTIFY_ID, builder.build());
}
댓글 없음:
댓글 쓰기