Pro Android with Kotlin


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

149
CHAPTER 8: APIs
Here are a few notes about this code:

KEY_TEXT_REPLY is used to identify the reply text in the intent receiver.

CONVERSATION_ID is used to identify the conversation chain; here the 
notification and the intent that receives the reply must know they refer to 
each other.

As usual, make sure that in production code you use string resources 
and appropriate text.
When the notification shows up, it will contain a Reply button, and when the user clicks 
it, the system will prompt for some reply text, which is then going to be sent to the intent 
receiver (messageReplyIntent in the example).
The intent receiver for the reply text might then have a receive callback that looks like this:
override fun onReceive(context: Context,
intent: Intent) {
Log.e("LOG", intent.toString())
val KEY_TEXT_REPLY = "key_text_reply"
val remoteInput = RemoteInput.
getResultsFromIntent(intent)
val txt = remoteInput?.
getCharSequence(KEY_TEXT_REPLY)?:"undefined"
val conversationId =
intent.getIntExtra("conversationId",0)
Log.e("LOG","reply text = " + txt)
// Do s.th. with the reply...
// Build a new notification, which informs the user
// that the system handled their interaction with
// the previous notification.
val NOTIFICATION_CHANNEL_ID = "1"
val repliedNotification =
NotificationCompat.Builder(context,
NOTIFICATION_CHANNEL_ID)
.setSmallIcon(android.R.drawable.ic_media_play)
.setContentText("Replied")
.build()
buildChannel(NOTIFICATION_CHANNEL_ID)
// Issue the new notification.
val notificationManager =
NotificationManagerCompat.from(context)
notificationManager.notify(conversationId,
repliedNotification)
}


150

Download 5.42 Mb.

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




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