Pro Android with Kotlin


Figure 8-3. Reply notification 148


Download 5.42 Mb.
Pdf ko'rish
bet130/223
Sana04.11.2023
Hajmi5.42 Mb.
#1746807
1   ...   126   127   128   129   130   131   132   133   ...   223
Bog'liq
@de android telegram Pro Android with Kotlin Developing Modern Mobile

Figure 8-3. Reply notification


148
CHAPTER 8: APIs
Since API levels below 24 are not able to provide that, your app should not rely on this 
functionality. Usually this is easy to achieve. For API levels 23 or lower, the activity called by 
tapping a notification can of course contain a facility to reply if needed.
A method that issues a notification with reply functionality might look like this:
fun directReply(view:View) {
// Key for the string that's delivered in the
// action's intent.
val KEY_TEXT_REPLY = "key_text_reply"
val remoteInput = RemoteInput.Builder(KEY_TEXT_REPLY)
.setLabel("Reply label")
.build()
// Make sure this broadcast receiver exists
val CONVERSATION_ID = 1
val messageReplyIntent =
Intent(this, MyReceiver2::class.java)
messageReplyIntent.action = "com.xyz2.MAIN"
messageReplyIntent.putExtra("conversationId",
CONVERSATION_ID)
// Build a PendingIntent for the reply
// action to trigger.
val replyPendingIntent = PendingIntent.
getBroadcast(applicationContext,
CONVERSATION_ID,
messageReplyIntent,
PendingIntent.FLAG_UPDATE_CURRENT)
// Create the reply action and add the remote input.
val action = NotificationCompat.Action.Builder(
... a resource id for an icon ...,
"Reply", replyPendingIntent)
.addRemoteInput(remoteInput)
.build()
val builder = NotificationCompat.Builder(this,
NOTIFICATION_CHANNEL_ID)
.setSmallIcon(... a resource id for an icon ...)
.setContentTitle("Title")
.setContentText("Content Content Content ...")
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
// add a reply action button
.addAction(action)
buildChannel(NOTIFICATION_CHANNEL_ID)
val notificationManager =
NotificationManagerCompat.from(this)
notificationManager.notify(
NOTIFICATION_ID, builder.build())
}



Download 5.42 Mb.

Do'stlaringiz bilan baham:
1   ...   126   127   128   129   130   131   132   133   ...   223




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling