You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

NotificationCompat.Builder.setStyle()类型不匹配:CallStyle与Style冲突

通话样式通知类型不匹配问题解决

我按照适用于通话应用的通话样式通知创建官方指南编写代码,代码如下:

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

但出现类型不匹配错误:

Required type:
Style
Provided:
CallStyle

解决方法

问题出在样式类的引用错误:NotificationCompat.Builder的setStyle方法要求传入NotificationCompat.Style的子类,而你使用的Notification.CallStyle是系统原生Notification类下的样式,二者类型不兼容。

只需将Notification.CallStyle替换为NotificationCompat.CallStyle即可,修改后的代码如下:

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

内容的提问来源于stack exchange,提问作者Yoav Gat

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 11:32:01