android - 在三星手机上进入 PIP(画中画)模式时出现错误 "Device doesn' t 支持画中画模式

标签 android samsung-mobile android-picture-in-picture

我在 Android O 手机(各种三星版本)上使用 PIP 模式,效果很好。但是,如果我打开辅助功能模式,我会得到

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

进入 PIP 模式时。在输入 PIP 之前,我会检查 PackageManager.FEATURE_PICTURE_IN_PICTURE 以及 AppOpsManager.OPSTR_PICTURE_IN_PICTURE 是否启用(两者都返回 true)。 “设备不支持画中画模式”的消息显然具有误导性和错误性,但是在这种情况下有什么方法可以检查 PIP 是否可用?
请注意,这似乎是三星唯一的问题,因为我尝试了各种三星手机和平板电脑(S8、Note 8、Tab S3、Tab S4),它们都崩溃了。 Google Pixel 3 手机没有这个问题。

最佳答案

我彻底浏览了相关文件的源代码,但找不到任何对我们可见的 API。所以现在,我已经放置了一个下面的解决方案,以防它也对你有帮助。

/**
 * 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;
}

关于android - 在三星手机上进入 PIP(画中画)模式时出现错误 "Device doesn' t 支持画中画模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55288858/

相关文章:

android - 如何在 Android 12 SplashScreen 中使用或退出

android - Samsung Galaxy 设备无法使用 geolocation.getCurrentPosition

android - 使用 Android O 画中画模式的任务列表和返回堆栈

flutter - 画中画模式如何进入jitsi session 室?

android - native 与混合移动应用程序

Android:存储在数据库中的缩略图返回空

java - 如何处理引用的库项目使用的库?

android - 三星我的文件资源管理器 : Pick file from specified folder

android - Galaxy S4 上的 float 触控

Android画中画模式,打开我的应用程序的另一个 Activity