Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launching Intent from notification opening in picture-in-picture window

I've followed the Android picture-in-picture documentation. That is to say, my PiP activity is marked android:launchMode="singleTask", android:resizeableActivity="true", and android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation" in the manifest.

Picture-in-picture seems to work great. However, I have noticed a case where I am experiencing undesirable behavior.

When my app receives a push, I create a PendingIntent with an Intent for MyActivity (different Activity than the PiP Activity). However, when I tap on the notification and the Intent is used, MyActivity is launching inside the PiP window!

I've tried adding android:launchMode="singleTask" to MyActivity in the manifest. I've also tried adding that flag programmatically to the Intent before using it with PendingIntent.getActivity(). This does not seem to fix the issue.

Can anyone tell me how to prevent this?

like image 437
Andrew Avatar asked Jan 03 '19 19:01

Andrew


People also ask

What is picture-in-picture in Android?

Picture-in-picture (PiP) shrinks a video into a small player so you can keep watching while using other apps on your mobile device. You can move the small player around your device's home screen and position it over other apps.

How do I get out of PiP mode?

The user can bring up a PIP menu that lets them toggle the PIP window to full-screen, or close the PIP window, by holding down the Home button on the remote.

How do you turn off picture-in-picture on android?

To disable the Picture-in-Picture mode Find and tap Settings > Apps & notifications > Advanced > Special app access > Picture-in-picture.


1 Answers

First of all, as you can see in google sample codes, it does not need to make the launch mode of PIP Activity singleTask. However, you need to move the launcher task to front which is not in PIP mode, in order to disabling PIP state.

By calling bellow snippet in the onCreate() method of the target Activity which is called from notifications, you can achieve this.

public static void moveLauncherTaskToFront(Context context) {
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    assert activityManager != null;
    final List<ActivityManager.AppTask> appTasks = activityManager.getAppTasks();
    for (ActivityManager.AppTask task : appTasks) {
        final Intent baseIntent = task.getTaskInfo().baseIntent;
        final Set<String> categories = baseIntent.getCategories();
        if (categories != null && categories.contains(Intent.CATEGORY_LAUNCHER)) {
            task.moveToFront();
            return;
        }
    }
}

---------------------- Before ---------------------------------------------- After ------------------------

enter image description here enter image description here

like image 63
aminography Avatar answered Oct 13 '22 03:10

aminography