gpt4 book ai didi

android - 接到 voip 电话时如何将 Activity 带到前台?

转载 作者:行者123 更新时间:2023-11-29 02:18:34 28 4
gpt4 key购买 nike

我正在开发一个 voip 调用应用程序。我需要做的是在接到来电时将 Activity 带到前台。我在应用程序中使用 Twilio,并在收到推送消息时开始调用。

问题是我试图在接到任何电话时显示 Activity ,以便用户可以轻松接听或拒绝来电。

我尝试在使用 setFullScreenIntent 时显示 Activity 但它不起作用。

在接听电话时,如何在不触摸通知的情况下将 Activity 带到前台?

private static final int      FULL_SCREEN_ID = 999;
private static final String CHANNEL_ID = "FULL_SCREEN_INTENT";

private void showFullScreenNotification(){

NotificationManager voipNotificationManager;
// Voip Notification Channel
voipNotificationManager = (NotificationManager) this.getSystemService(
Context.NOTIFICATION_SERVICE);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(
CHANNEL_ID, "Notification",
NotificationManager.IMPORTANCE_HIGH);
channel.setLockscreenVisibility(NotificationCompat.VISIBILITY_PUBLIC);
channel.setImportance(NotificationManager.IMPORTANCE_HIGH);
channel.enableLights(true);
if (voipNotificationManager != null) {
voipNotificationManager.createNotificationChannel(channel);
}
}
Intent fullScreenIntent = new Intent(this, FullScreenIntent.class);
fullScreenIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
fullScreenIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
fullScreenIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(this, 0,
fullScreenIntent, PendingIntent.FLAG_UPDATE_CURRENT);

NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_launcher_background)
.setContentTitle("My notification")
.setContentText("Hello guys!")
//.setOnlyAlertOnce(false)
.setCategory(NotificationCompat.CATEGORY_CALL)
//.setOngoing(true)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setFullScreenIntent(fullScreenPendingIntent, true);
builder.build();

voipNotificationManager.notify(FULL_SCREEN_ID,builder.build());
}

我也尝试过这些解决方案

最佳答案

尝试:

Intent intent = new Intent( this, AnyBackgroundActivity.class );
intent.setFlags( FLAG_ACTIVITY_REORDER_TO_FRONT );
startActivity( intent );

FLAG_ACTIVITY_REORDER_TO_FRONT Added in API level 3 public static final int FLAG_ACTIVITY_REORDER_TO_FRONT If set in an Intent passed to Context#startActivity, this flag will cause the launched activity to be brought to the front of its task's history stack if it is already running.

For example, consider a task consisting of four activities: A, B, C, D. If D calls startActivity() with an Intent that resolves to the component of activity B, then B will be brought to the front of the history stack, with this resulting order: A, C, D, B. This flag will be ignored if FLAG_ACTIVITY_CLEAR_TOP is also specified.

关于android - 接到 voip 电话时如何将 Activity 带到前台?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58058886/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com