Android 8.0.0 Only fullscreen op

2020-09-25  本文已影响0人  贼噶人

发生异常代码

@MainThread
    @CallSuper
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        if (DEBUG_LIFECYCLE) Slog.v(TAG, "onCreate " + this + ": " + savedInstanceState);
        if (getApplicationInfo().targetSdkVersion > O && mActivityInfo.isFixedOrientation()) {
            final TypedArray ta = obtainStyledAttributes(com.android.internal.R.styleable.Window);
            final boolean isTranslucentOrFloating = ActivityInfo.isTranslucentOrFloating(ta);
            ta.recycle();
            if (isTranslucentOrFloating) {
                throw new IllegalStateException(
                        "Only fullscreen opaque activities can request orientation");
            }
        }

可以看到其执行有个判断条件,所以我们想办法破坏其条件使其不成立就行

解决办法如下,重写Actvity的 attchBaseContext方法修改TargetSdkVersion字段的值,使其判断条件不成立


    @Override
    protected void attachBaseContext(Context newBase) {
        super.attachBaseContext(newBase);
        if ("8.0.0".equals(Build.VERSION.RELEASE)) {
            getApplicationInfo().targetSdkVersion
                    = Build.VERSION_CODES.O;
        }
    }
上一篇下一篇

猜你喜欢

热点阅读