Android Jetpack - Notification
概要
種類
使用方法
最も基本的なテキストのみを送信する目覚まし時計です.
val channelID = "CHANNELID"
val notificationChannel = NotificationChannel(
channelID,
"TestChannelName",
NotificationManager.IMPORTANCE_DEFAULT
)
val builder = NotificationCompat.Builder(this, channelID)
.setSmallIcon(R.drawable.ic_launcher_foreground)
.setContentTitle("Title")
.setContentText("ContentText")
val notificationManager: NotificationManager =
getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(notificationChannel)
notificationManager.notify(
1, // 해당 알림의 고유 ID
builder // 표시할 알림
.setContentTitle("title")
.setContentText("content")
.build()
)
「≪アラート|Alerts|emdw≫」をクリックすると、特定のアクティビティに移動し、アラートを削除します.
val intent = Intent(this, NextActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_CLEAR_TASK // 앱 스택 관련처리 부분 굳이 없어도 작동은 함
}
val pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
notificationManager.notify(
1, // 해당 알림의 고유 ID
builder // 표시할 알림
.setContentTitle("title")
.setContentIntent(pendingIntent)
.setContentText("content")
.setAutoCancel(true)
.build()
)
目覚まし時計にボタンを追加
val pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
val action = NotificationCompat.Action.Builder(R.drawable.ic_launcher_foreground, "TestAction", pendingIntent).build()
notificationManager.notify(
1, // 해당 알림의 고유 ID
builder // 표시할 알림
.setContentTitle("title")
.addAction(action)
.setContentText("content")
.setAutoCancel(true)
.build()
)
Reference
この問題について(Android Jetpack - Notification), 我々は、より多くの情報をここで見つけました https://velog.io/@arakene/Android-Jetpack-Notificationテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol