Created
November 27, 2019 08:02
-
-
Save pyeongho/341435dcb47b87b81026f3afd00434ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val NOTIFICATION_ID = 1001; | |
createNotificationChannel(this, NotificationManagerCompat.IMPORTANCE_HIGH, false, | |
getString(R.string.app_name), "App notification channel") // 1 | |
val channelId = "$packageName-${getString(R.string.app_name)}" | |
val title = "Android Developer" | |
val content = "Notifications in Android P" | |
val intent = Intent(baseContext, NewActivity::class.java) | |
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK | |
val fullScreenPendingIntent = PendingIntent.getActivity(baseContext, 0, | |
intent, PendingIntent.FLAG_UPDATE_CURRENT) // 2 | |
val builder = NotificationCompat.Builder(this, channelId) | |
builder.setSmallIcon(R.drawable.ic_codechacha) | |
builder.setContentTitle(title) | |
builder.setContentText(content) | |
builder.priority = NotificationCompat.PRIORITY_HIGH // 3 | |
builder.setAutoCancel(true) | |
builder.setFullScreenIntent(fullScreenPendingIntent, true) // 4 | |
val notificationManager = NotificationManagerCompat.from(this) | |
notificationManager.notify(NOTIFICATION_ID, builder.build()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment