项目要求实现APP横屏显示,在网上找了很多方法都不管用,因此直接从packageParser.java入手解决:
一、打开frameworks/base/core/java/android/content/pm/PackageParser.java
- a.info.screenOrientation = sa.getInt(
- R.styleable.AndroidManifestActivity_screenOrientation,
- SCREEN_ORIENTATION_UNSPECIFIED);
//add by
+ if(SystemProperties.getInt("persist.sys.force_land_enabled", 1) == 1){
+ a.info.screenOrientation = SCREEN_ORIENTATION_LANDSCAPE;
+ }else{
+ a.info.screenOrientation = sa.getInt(
+ R.styleable.AndroidManifestActivity_screenOrientation,
+ SCREEN_ORIENTATION_UNSPECIFIED);
+ }
+ //end
setActivityResizeMode(a.info, sa, owner);
二、打开/frameworks/base/core/java/android/content/pm/parsing/component/ParsedActivityUtils.java
- int screenOrientation = sa.getInt(R.styleable.AndroidManifestActivity_screenOrientation, SCREEN_ORIENTATION_UNSPECIFIED);
+ //add by
+ int screenOrientation;
+
+ Log.d(TAG, "persist.sys.force_land_enabled = " + SystemProperties.getInt("persist.sys.force_land_enabled", 1));
+
+ if(SystemProperties.getInt("persist.sys.force_land_enabled", 1) == 1){
+ screenOrientation = SCREEN_ORIENTATION_LANDSCAPE;
+ }else {
+ screenOrientation = sa.getInt(R.styleable.AndroidManifestActivity_screenOrientation, SCREEN_ORIENTATION_UNSPECIFIED);
+ }
+ //end
+
三、打开/frameworks/base/services/core/java/com/android/server/wm/ActivityClientController.java
@@ -636,7 +637,12 @@ class ActivityClientController extends IActivityClientController.Stub {
synchronized (mGlobalLock) {
final ActivityRecord r = ActivityRecord.isInRootTaskLocked(token);
if (r != null) {
- r.setRequestedOrientation(requestedOrientation);
+ // add by
+ if(SystemProperties.getInt("persist.sys.force_land_enabled", 1) == 1) {
+ r.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
+ }else{
+ r.setRequestedOrientation(requestedOrientation);
+ }
}
}
} finally {
至此,完美解决横屏问题!