8

In Android Oreo. The activity can go into pip mode and go back to launcher.

https://developer.android.com/guide/topics/ui/picture-in-picture.html

Now I am the launcher. Is there any way to know currently there is a pip windows displayed on the screen?

isInPictureInPictureMode() only indicate your application pipmode, which will be false if there is other app go into the pip mode.

The intent flags were the same when you exit application and go to pipmode back to launcher.

12-15 03:31:39.580 11671 11671 D FLAG_ACTIVITY_FORWARD_RESULT
12-15 03:31:39.580 11671 11671 D FLAG_ACTIVITY_NEW_TASK
12-15 03:31:39.580 11671 11671 D FLAG_ACTIVITY_PREVIOUS_IS_TOP
12-15 03:31:39.581 11671 11671 D FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
12-15 03:31:39.581 11671 11671 D FLAG_RECEIVER_BOOT_UPGRADE
12-15 03:31:39.581 11671 11671 D FLAG_RECEIVER_FOREGROUND
12-15 03:31:39.581 11671 11671 D FLAG_RECEIVER_INCLUDE_BACKGROUND
12-15 03:31:39.581 11671 11671 D FLAG_RECEIVER_VISIBLE_TO_INSTANT_APPS
12-15 03:31:50.174 11671 11671 D FLAG_ACTIVITY_FORWARD_RESULT
12-15 03:31:50.174 11671 11671 D FLAG_ACTIVITY_NEW_TASK
12-15 03:31:50.174 11671 11671 D FLAG_ACTIVITY_PREVIOUS_IS_TOP
12-15 03:31:50.174 11671 11671 D FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
12-15 03:31:50.174 11671 11671 D FLAG_RECEIVER_BOOT_UPGRADE
12-15 03:31:50.174 11671 11671 D FLAG_RECEIVER_FOREGROUND
12-15 03:31:50.174 11671 11671 D FLAG_RECEIVER_INCLUDE_BACKGROUND
12-15 03:31:50.174 11671 11671 D FLAG_RECEIVER_VISIBLE_TO_INSTANT_APPS

I check the pip mode source code and they control this by the WindowManagerService. I don't think it can be accessed through the application level.

reVerse
  • 35,075
  • 22
  • 89
  • 84
Shu Zhang
  • 521
  • 12
  • 20
  • 1
    one way is that you can build an `AccessibilityService` which can query the `AccessibilityWindowInfo`s for `isInPictureInPictureMode()`. Note that Google is currently (late 2017) hunting down the abuse of accessibility service feature, so be cautious. Use this only if you couldn't find a better solution. https://developer.android.com/reference/android/view/accessibility/AccessibilityWindowInfo.html#isInPictureInPictureMode() – Madushan Dec 18 '17 at 09:22
  • I query the Windows using `List windows = getWindows();` in the ServiceConnected. Where it contains nothing, is that normal? Also this method requires open accessibility manually. – Shu Zhang Dec 18 '17 at 10:46
  • 1
    You need to request certain permissions for Accessibility Service to work. The user has to approve the registration of it. See https://developer.android.com/training/accessibility/service.html – Madushan Dec 18 '17 at 10:58
  • Cool. this solution works with limits. the flag is called FLAG_RETRIEVE_INTERACTIVE_WINDOWS. Detail was specified on the comment of the functions `getWindows();` But this requires user to interact of Accessibility in Setting. It's would be nice to have fully user-react free solution. – Shu Zhang Dec 19 '17 at 08:32
  • Interesting there's no other public API to do this. I'll post this as an answer for now until someone finds a better solution. – Madushan Dec 19 '17 at 10:26
  • hmm did you find other way to check it? – famfamfam Sep 19 '20 at 05:27
  • No other solution yet, I think. – Shu Zhang Sep 19 '20 at 06:11

1 Answers1

0

you can build an AccessibilityService which can query the AccessibilityWindowInfos for isInPictureInPictureMode().

Note that Google is currently (late 2017) hunting down the abuse of accessibility service feature, so be cautious. This approach will very likely count as an abuse. Use this only if you couldn't find a better solution.

See Developing an Accessibility Service for a guide.

Note that this requires prompting for user's permission and the user has to explicitly accept the Accessibility Service.

Madushan
  • 6,977
  • 31
  • 79