Как вывести активность на передний план при получении VoIP-звонка? - PullRequest
0 голосов
/ 23 сентября 2019

Я занимаюсь разработкой приложения для VoIP-звонков.Что мне нужно сделать, это вывести активность на передний план при получении входящего вызова.Я использую Twilio в приложении и отправляю push-сообщение при получении любого вызова.

Проблема в том, что я пытаюсь показать активность при получении любого вызова, чтобы пользователь мог легко принять или отклонить вызов.

Я пытаюсь отобразить активность при использовании setFullScreenIntent , но она не работает.

Как вывести активность на передний план, не касаясь уведомления при получении вызова?

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());
    }

Я также попробовал эти решения

...