【问题标题】:In Android, make Caller ID notification visually appear on screen when there is incoming call?在Android中,当有来电时,让来电显示通知直观地显示在屏幕上?
【发布时间】:2021-06-11 06:17:05
【问题描述】:

我们正在开发一款可以通过电话号码识别来电名称的应用。 (我们的问题类似于this one,但解决方案不同)我们创建了一个CallScreeningService,它接收来电的电话号码,并且我们能够在有电话时显示显示来电显示的toast。但是,我们想要显示通知,而不是显示 toast。 (我们也尝试过显示pop up window over Android native incoming call screen like true caller Android app,但在应用程序处于后台或关闭状态时无法显示)现在我们还可以在有电话时创建来电显示通知,但它不会在屏幕上直观显示.

是否可以让通知在来电的同时直观地显示在屏幕上?如果是,怎么做?

非常感谢!

【问题讨论】:

  • 澄清一下,您是否尝试过使用 <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> 和概率结合前台服务的浮动小部件(也称为显示在其他应用程序上)?

标签: android android-notifications caller-id callscreeningservice


【解决方案1】:

假设您找到了让应用在打盹模式下保持活动状态的方法,您需要将通知的频道重要性或通知的优先级设置为高或最高(旁注:通知频道的重要性会覆盖通知构建器的优先级)。

通知频道:

NotificationChannel chan = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_HIGH);

通知生成器:

NotificationCompat.Builder mBuilder =
            (NotificationCompat.Builder) new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.some_small_icon)
            .setContentTitle("Title")
            .setContentText("This is a test notification with MAX priority")
            .setPriority(Notification.PRIORITY_MAX);

如果打盹模式正在杀死您的应用,您可以使用前台服务并返回 Service.START_STICKY;或 WakefulBroadcastReceiver 与 startWakefulService() 混合。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多