Mobile app does not display full screen on tablet

Option 1: Through my own demo testing, I learned that the following code can make the current window display in full screen

    private void setWindow(){
        WindowManager m = getWindowManager();
        Display d = m.getDefaultDisplay();  //为获取屏幕宽、高
        android.view.WindowManager.LayoutParams p = getWindow().getAttributes();  //获取对话框当前的参数值
        p.height = (int) (d.getHeight());   //高度设置为屏幕的0.6
        p.width = (int) (d.getWidth());    //宽度设置为屏幕的0.95
        getWindow().setAttributes(p);     //设置生效
    }

Since the integrated app does not have source code, look for the specific implementation of the setAttributes method in the system source code.

The actual resolution of the device is 1920x1080. In this method, the width and height are directly reassigned to 1920x1080.

Option II:

--- a/core/java/android/app/Activity.java
+++ b/core/java/android/app/Activity.java
@@ -6671,13 +6671,37 @@ public class Activity extends ContextThemeWrapper
     public void setRequestedOrientation(@ActivityInfo.ScreenOrientation int requestedOrientation) {
         if (mParent == null) {
             try {
-                ActivityTaskManager.getService().setRequestedOrientation(
-                        mToken, requestedOrientation);
-            } catch (RemoteException e) {
+//                ActivityTaskManager.getService().setRequestedOrientation(
+//                        mToken, requestedOrientation);
+               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) {
                 // Empty
             }
         } else {
-            mParent.setRequestedOrientation(requestedOrientation);
+//            mParent.setRequestedOrientation(requestedOrientation);
+            try {
+               if(mApplication != null && mApplication.getApplicationInfo() != null
+                                   && mApplication.getApplicationInfo().uid > 10000){
+                      ActivityTaskManager.getService().setRequestedOrientation(
+                         mToken, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
+               }else{
+                       mParent.setRequestedOrientation(requestedOrientation);
+               }
+            } catch (RemoteException e) {
+                // Empty
+            }
         }
     }

diff --git a/core/java/android/content/pm/parsing/component/ParsedActivityUtils.java b/core/java/android/content/pm/parsing/component/ParsedActivityUtils.java
index fb8fd74545c..0f8f7e35c34 100644
--- a/core/java/android/content/pm/parsing/component/ParsedActivityUtils.java
+++ b/core/java/android/content/pm/parsing/component/ParsedActivityUtils.java
@@ -146,7 +146,16 @@ public class ParsedActivityUtils {
                         sa.getInt(R.styleable.AndroidManifestActivity_configChanges, 0),
                         sa.getInt(R.styleable.AndroidManifestActivity_recreateOnConfigChanges, 0));

-                int screenOrientation = sa.getInt(R.styleable.AndroidManifestActivity_screenOrientation, SCREEN_ORIENTATION_UNSPECIFIED);
+                //int screenOrientation = sa.getInt(R.styleable.AndroidManifestActivity_screenOrientation, SCREEN_ORIENTATION_UNSPECIFIED);
+               int screenOrientation;
+               if (pkg.getSharedUserId() == null){
+                       screenOrientation = 0;
+               }else{
+                       screenOrientation = sa.getInt(R.styleable.AndroidManifestActivity_screenOrientation, SCREEN_ORIENTATION_UNSPECIFIED);
+               }
                 int resizeMode = getActivityResizeMode(pkg, sa, screenOrientation);
                 activity.screenOrientation = screenOrientation;
                 activity.resizeMode = resizeMode;

Guess you like

Origin blog.csdn.net/MilesMatheson/article/details/130793724
Recommended