9

I'm using PIP mode on Android O phone (various Samsung versions) and it works fine. However, if I turn on accessibility mode I get

java.lang.IllegalStateException·enterPictureInPictureMode: Device doesn't support picture-in-picture mode

when entering PIP mode. Before entering PIP I do check PackageManager.FEATURE_PICTURE_IN_PICTURE and if AppOpsManager.OPSTR_PICTURE_IN_PICTURE is enabled (both return true). The message "Device doesn't support picture-in-picture mode" is obviously misleading and wrong but is there any way to check if PIP is available in this case?
Note that this appears to be Samsung only problem as I tried various Samsung phones and tablets (S8, Note 8, Tab S3, Tab S4) and they all crashed. Google Pixel 3 phone did not have this problem.

alexbtr
  • 3,292
  • 2
  • 13
  • 25

1 Answers1

-1

I thoroughly went through the source code of related files but couldn't find any API visible to us. SO for now, I have placed a below solution, in case it helps you as well.

/**
 * Trying to enter Picture In Picture mode on a Samsung device while an accessibility service
 * that provides spoken feedback would result in an IllegalStateException.
 */

public static boolean isScreenReaderActiveAndTroublesome(Activity activity) {
    final String affectedManufacturer = "samsung";
    final String deviceManufacturer = android.os.Build.MANUFACTURER.toLowerCase();

    if (affectedManufacturer.equals(deviceManufacturer)) {
        final AccessibilityManager am =
                (AccessibilityManager) activity.getSystemService(Context.ACCESSIBILITY_SERVICE);
        final List<AccessibilityServiceInfo> enabledScreenReaderServices =
                am.getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_SPOKEN);

        final boolean isScreenReaderServiceActive = !enabledScreenReaderServices.isEmpty();

        if (isScreenReaderServiceActive) {
            Log.e(TAG, "Screen reader is active on this Samsung device, PIP would be disabled");
        }

        return isScreenReaderServiceActive;
    }

    return false;
}
prateek
  • 440
  • 4
  • 12
  • 1
    Thanks for the answer. I think a better solution is to put try/catch around enterPictureInPictureMode in onUserLeaveHint. It covers all the possible cases including Samsung specific case and if Samsung fixes the bug it will just work without making any code changes. However, it still doesn't answer the main question about making it work on Samsung devices. – alexbtr Feb 04 '20 at 20:27