android - 在Android中,当有来电时,让来电显示通知直观地显示在屏幕上?

标签 android android-notifications caller-id callscreeningservice

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

最佳答案

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

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() 混合。

关于android - 在Android中,当有来电时,让来电显示通知直观地显示在屏幕上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67932082/

相关文章:

android - 每天同一时间通知

ios - 有没有办法在 iOS 中使用 Call Directory Extension 阻止 No Caller ID?

c# - 使用 USR5637 调制解调器时转换来电显示格式?

ios - 调用目录分机的来电显示中的 UserDefaults

android - 在目录 React Native 中找不到已签名的 Apk - Android

android - 如何在具有三个平移布局的嵌套 fragment 中添加动态 fragment

android - MediaSession 和 MediaSessionManager 是否向后兼容?

android - DownloadManager setVisibleInDownloadsUi 不起作用

android - 如何从具有ROOT权限的Android应用程序启动进程

java - 使用异步函数分配全局变量