γϯϓϧͳ࣮ val notification = NotificationCompat.Builder(context, CH_ID_NORMAL) .setContentTitle("This is title") .setContentText("This is message") .setSmallIcon(R.drawable.ic_notification) .build() val nm = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager nm.notify(1, notification)
Direct Reply val notification = NotificationCompat.Builder(context, CHANNEL_ID_NORMAL) ... .addAction(action) .build() val nm = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager nm.notify(1, notification)
Big Text Style࣮ val style = NotificationCompat.BigTextStyle() .setBigContentTitle("Big content title") .setSummaryText("Big text summary") .bigText("This is long text. This is long text. This is long text. This is long text. This is long text.") val notification = NotificationCompat.Builder(context, CHANNEL_ID_NORMAL) .setContentTitle("This is title") .setContentText("This is message") .setTicker("This is ticker") // for legacy Android .setStyle(style) ... .build() val nm = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager nm.notify(1, notification)
Big Text Style࣮ val style = NotificationCompat.BigTextStyle() .setBigContentTitle("Big content title") .setSummaryText("Big text summary") .bigText("This is long text. This is long text. This is long text. This is long text. This is long text.") val notification = NotificationCompat.Builder(context, CHANNEL_ID_NORMAL) .setContentTitle("This is title") .setContentText("This is message") .setTicker("This is ticker") // for legacy Android .setStyle(style) ... .build() val nm = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager nm.notify(1, notification) StyleͷΠϯελϯε࡞
Big Text Style࣮ val style = NotificationCompat.BigTextStyle() .setBigContentTitle("Big content title") .setSummaryText("Big text summary") .bigText("This is long text. This is long text. This is long text. This is long text. This is long text.") val notification = NotificationCompat.Builder(context, CHANNEL_ID_NORMAL) .setContentTitle("This is title") .setContentText("This is message") .setTicker("This is ticker") // for legacy Android .setStyle(style) ... .build() val nm = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager nm.notify(1, notification)
Colorized • ਐߦதͷॏཁͳ௨ʹͷΈɺഎܠ৭Λ͚Δ͜ͱ͕Ͱ͖Δ • ௨தɺΧʔφϏͳͲ • Foreground ServiceͱηοτͰ͏ • ςΩετΧϥʔഎܠ৭͔ΒࣗಈͰܾ·ΔʢઃఆෆՄʣ • BLACK or WHITE • ίϯτϥετΛߟྀͨ͠എܠ৭Λઃఆ͢Δ͜ͱ • API 26Ҏ߱
௨νϟϯωϧͷ࡞ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { val channel1 = NotificationChannel(CHANNEL_ID_NORMAL, "ී௨ͷνϟϯωϧ", NotificationManager.IMPORTANCE_DEFAULT) val channel2 = NotificationChannel(CHANNEL_ID_IMPORTANT, "ॏཁͳνϟϯω ϧ", NotificationManager.IMPORTANCE_HIGH) val nm = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager nm.createNotificationChannel(channel1) nm.createNotificationChannel(channel2) } API 26Ҏ߱ͷΈ࣮ߦ
௨νϟϯωϧͷࢦఆ val notification = NotificationCompat.Builder(context, CH_ID_NORMAL) .setContentTitle("This is title") .setContentText("This is message") .setSmallIcon(R.drawable.ic_notification) .build() val nm = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager nm.notify(1, notification) νϟϯωϧIDΛࢦఆ
ϔουΞοϓ࣮ val notification = NotificationCompat.Builder(context, CHANNEL_ID_IMPORTANT) ... .setPriority(Notification.PRIORITY_HIGH) .build() val nm = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager nm.notify(1, notification) API 26Ҏ߱ API 25ҎԼ
PublicʢϩοΫը໘༻ʣ val publicNotification = NotificationCompat.Builder(context, CHANNEL_ID_NORMAL) .setContentTitle("This is public title") .setContentText("This is public message") ... .build()