【问题标题】:how to Display time-sensitive notifications in android如何在android中显示时间敏感的通知
【发布时间】:2023-03-20 15:42:01
【问题描述】:

在限制从 android 后台启动活动之后 Q 我正在尝试使用 developer.android 示例代码为我的 VOIP 呼叫构建通知,但它不工作你能帮我解决这个问题吗?

下面的代码是我用来构建时间敏感通知的示例:

  Intent fullScreenIntent = new Intent(this, CallActivity.class);
                    PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(this, 0,
                            fullScreenIntent, PendingIntent.FLAG_UPDATE_CURRENT);

                    NotificationCompat.Builder notificationBuilder =
                            new NotificationCompat.Builder(this, CHANNEL_ID)
                                    .setSmallIcon(R.drawable.notification_icon)
                                    .setContentTitle("Incoming call")
                                    .setContentText("(919) 555-1234")
                                    .setPriority(NotificationCompat.PRIORITY_HIGH)
                                    .setCategory(NotificationCompat.CATEGORY_CALL)
                                    .setFullScreenIntent(fullScreenPendingIntent, true);

                    Notification incomingCallNotification = notificationBuilder.build();

【问题讨论】:

  • 你能帮忙 startForeground(notificationId, notification);我不确定 startForeground 在哪里定义

标签: android android-notifications android-10.0


【解决方案1】:

由于您使用的是 Android 10,因此您需要申请 USE_FULL_SCREEN_INTENT 权限。在你的AndroidManifest.xml:

<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />

见:https://developer.android.com/about/versions/10/behavior-changes-10#full-screen-intents

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-05
  • 1970-01-01
  • 2018-02-28
相关资源
最近更新 更多