Android 11强制所有应用横屏展示
1、打开frameworks/base/core/java/android/content/pm/parsing/component/ParsedActivityUtils.java文件,定位到parseActivityOrReceiver方法的int screenOrientation = sa.getInt(R.styleable.AndroidManifestActivity_screenOrientation, SCREEN_ORIENTATION_UNSPECIFIED);这一行,注释掉该行并添加如下代码:
// int screenOrientation = sa.getInt(R.styleable.AndroidManifestActivity_screenOrientation, SCREEN_ORIENTATION_UNSPECIFIED);
// Edit by jgduan
int screenOrientation;
if(pkg.getSharedUserId() == null){
screenOrientation = 0;
} else {
screenOrientation = sa.getInt(R.styleable.AndroidManifestActivity_screenOrientation, SCREEN_ORIENTATION_UNSPECIFIED);
}
// End
2、打开frameworks/base/core/java/android/app/Activity.java文件,对setRequestedOrientation方法进行如下修改:
public void setRequestedOrientation(@ActivityInfo.ScreenOrientation int requestedOrientation) {
if (mParent == null) {
try {
if(mApplication != null && mApplication.getApplicationInfo() != null
&& mApplication.getApplicationInfo().uid > 10000){
ActivityTaskManager.getService().setRequestedOrientation(
mToken, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else {
ActivityTaskManager.getService().setRequestedOrientation(
mToken, requestedOrientation);
}
} catch (RemoteException e) {
}
} else {
if(mApplication != null && mApplication.getApplicationInfo() != null
&& mApplication.getApplicationInfo().uid > 10000){
mParent.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}else{
mParent.setRequestedOrientation(requestedOrientation);
}
}
}
-END-
|