Android 8.0.0 Only fullscreen op
作者:
贼噶人 | 来源:发表于
2020-09-25 17:19 被阅读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;
}
}
本文标题:Android 8.0.0 Only fullscreen op
本文链接:https://www.haomeiwen.com/subject/dfifuktx.html
网友评论