# Android Oreo Notification Channel Alarm
```java
//TODO SOFTM 20190103 - oreo8 alarm
final static String NOTI_MODE_SILENT = "MY_NOTI_SILENT";
final static String NOTI_MODE_VIBRATION = "MY_NOTI_VIBRATION";
final static String NOTI_MODE_SOUND = "MY_NOTI_SOUND";
final static String NOTI_MODE_FOOD_REFRESH = "MY_NOTI_FOOD_REFRESH";
final static String NOTI_MODE_SILENT_NAME = "무음";
final static String NOTI_MODE_VIBRATION_NAME = "진동";
final static String NOTI_MODE_SOUND_NAME = "소리";
final static String NOTI_MODE_FOOD_REFRESH_NAME = "FOOD";
public void buildNotification(Context context) {
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
Resources res = context.getResources();
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.setAction(Intent.ACTION_VIEW);
intent.setComponent(new ComponentName(context, MainWebviewActivity.class));
intent.setData(Uri.parse("mymobile://mylink?" +
"from=" + PushLibraryAppReceiver.class.getSimpleName() +
"&url=" + URLClass.MESSAGE_LIST_URL
));
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context,NOTI_MODE_SILENT); //TODO SOFTM 20181221 - PUSH - add channel
builder.setContentTitle(pushTitle);
builder.setContentText(pushContent);
builder.setTicker(pushTitle);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
builder.setLargeIcon(BitmapFactory.decodeResource(res, R.mipmap.ic_launcher));
builder.setSmallIcon(R.drawable.push_icon);
builder.setColor(Color.parseColor("#376dc8"));
}
else {
builder.setSmallIcon(R.mipmap.ic_launcher);
}
builder.setContentIntent(pendingIntent);
builder.setAutoCancel(true);
builder.setWhen(System.currentTimeMillis());
String ringType = MyApp.getInstance().getPushRingType();
if(ringType.equals("1")){//소리
builder.setDefaults(Notification.DEFAULT_SOUND);
builder.setChannelId(NOTI_MODE_SOUND); //TODO SOFTM 20190103 - oreo8 alarm
}else if(ringType.equals("2")){//진동
builder.setDefaults(Notification.DEFAULT_VIBRATE);
builder.setChannelId(NOTI_MODE_VIBRATION); //TODO SOFTM 20190103 - oreo8 alarm
}else {// 무음
builder.setChannelId(NOTI_MODE_SILENT); //TODO SOFTM 20190103 - oreo8 alarm
}
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
builder.setCategory(Notification.CATEGORY_MESSAGE)
.setPriority(Notification.PRIORITY_HIGH)
.setVisibility(Notification.VISIBILITY_PUBLIC);
}
MyApp.getInstance().setNotiBadge();
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify((int)pushRecprSeq, builder.build());
}
```
댓글