4

I'm developing an voip call app. What I need to do is bring activity to the foreground when receiving incoming call. I'm using Twilio in application and I start the call when push message receive.

The problem is I'm trying to show up activity when receiving any call so the user can easily accept or decline the call.

I try to display activity while using setFullScreenIntent but its not work.

How can I bring activity to the foreground without touching notification when receiving call ?

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

I also tried these solutions

abdlkdr
  • 152
  • 2
  • 14

1 Answers1

0

Try:

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.

RonTLV
  • 2,376
  • 2
  • 24
  • 38