Search code examples
androidandroid-notifications

NotificationCompat.Builder.setStyle() type mismatch with CallStyle


I am following this official guide for creating a call style notification for calling apps. In my code:

notification = new NotificationCompat.Builder(this, CHANNEL_ID)
                    .setContentTitle("appName")
                    .setContentText("Running call...")
                    .setSmallIcon(R.drawable.ic_call)
                    .setStyle(Notification.CallStyle.forOngoingCall(incomingCaller, hangupPendingIntent))
                    .build();

I am getting a type mismatch:

Required type:
Style
Provided:
CallStyle

Solution

  • My mistake, I just needed to use NotificationCompat.CallStyle since I'm using NotificationCompat instead of Notification:

    .setStyle(NotificationCompat.CallStyle.forOngoingCall(incomingCaller, declinePendingIntent))