Reputation: 56
Starting in Android 12, CallStyle is introduced for creating call-related notifications. And I'm using NotificationCompat to support backward compatibility. Everything works fine if used the Notification library but when I used the NotificationCompat, I encountered an issue.
This is basically how I created an incoming call notification.
NotificationCompat.Builder(this, notifificationChannelId)
.setSmallIcon(android.R.drawable.ic_menu_call)
.setContentTitle("Caller 1")
.setContentText("Incoming Call")
.setAutoCancel(true)
.addAction(extraAction1)
.setStyle(NotificationCompat.CallStyle.forIncomingCall(
caller,
pendingServiceIntent,
pendingServiceIntent
))
.setContentIntent(pendingActivityIntent)
.setFullScreenIntent(pendingActivityIntent, true)
.setOngoing(true)
.setOnlyAlertOnce(true)
.addPerson(caller)
.setColorized(true)
.build()
In this line,
.addAction(extraAction1)
This will be the custom action. Based on Android documentation, we should be able to add one custom action.
But it seems not working at all. The default buttons (Decline & Answer) showed up, but the custom action ```extraAction1```` I added, didn't show up.
Any ideas what I might be missing?
Upvotes: 0
Views: 787
Reputation: 1
It seems to work for me. I believe you also wrote extraAction1 code as below?
> extraAction1 =
> NotificationCompat.Action.Builder(
> IconCompat.createWithResource(context, R.drawable.call_24px),
> "My Text",
> myPendingIntent
> ).build()
Upvotes: 0
Reputation: 1
Despite the doc saying it is supported, the NotificationCompat
class so far does not. See this Google issue
Upvotes: 0
Reputation: 490
You should try use CallStyle.forScreeningCall
instead of CallStyle.forIncommingCall
Creates a CallStyle for a call that is being screened. This notification will have a hang up and an answer action, will allow a single custom action, and will have a default content text for a call that is being screened.
Upvotes: 0