如何以编程方式更改屏幕分辨率?

发布于 2024-10-11 11:18:35 字数 169 浏览 2 评论 0原文

让我告诉你我的问题。我想更改屏幕分辨率。 我可以在应用程序中更改它,但它仅更改应用程序的 屏幕。我想设置系统的分辨率,所以哪个并不重要 应用程序在前面运行。我的设备分辨率设置为1280 * 720 页。可以做成1260*680吗?如果需要进行更改 Android源码,我可以。只要告诉我哪里需要改变就可以了。等待 你的帮助。

Let me tell you my problem. I want to change my screen resolution.
I can change it in an application but it changes only application's
screen. I wanna set system's resolution so it won't be important which
application is running on front. My device's resolution is set as 1280
* 720 p. Can I make it 1260 * 680? If it requires to make changes in
Android source code, I can. Just tell me where to change. Waiting for
your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

你在看孤独的风景 2024-10-18 11:18:36

xda-developers 上的这个帖子应该会让您走上正确的道路。

This thread on xda-developers should set you on the right track.

不必了 2024-10-18 11:18:36

也搜索了一个有效的答案,但我找到了解决方案:
警告实验性错误:

/*
Requires android.permission.WRITE_SETTINGS
and android.permission.WRITE_SECURE_SETTINGS, thus it requires the app to be a system app.
 */
public void changeResolution(int x, int y){
    try { Class c = Class.forName("android.os.ServiceManager");
        try { Method method = c.getDeclaredMethod("checkService", String.class);
            try {
                IWindowManager mWindowManager = IWindowManager.Stub.asInterface((IBinder) method.invoke(null,Context.WINDOW_SERVICE));
                try { mWindowManager.setForcedDisplaySize(Display.DEFAULT_DISPLAY,x,y);
                } catch (RemoteException e) {e.printStackTrace();}
            }  catch (IllegalAccessException e) {e.printStackTrace();}
            catch (InvocationTargetException e) {e.printStackTrace();}
        } catch (NoSuchMethodException e) {e.printStackTrace();}
    } catch (ClassNotFoundException e) {e.printStackTrace();}
}

将 IWindowManager 的简化 AIDL 版本添加到您的项目中:
/app/src/main/aidl/android/view/IWindowManager.aidl

package android.view;
interface IWindowManager
{
    boolean startViewServer(int port);   // Transaction #1
    boolean stopViewServer();            // Transaction #2
    boolean isViewServerRunning();       // Transaction #3

    void setForcedDisplaySize(int displayId, int width, int height);
    void clearForcedDisplaySize(int displayId);
    void setForcedDisplayDensity(int displayId, int density);
    void clearForcedDisplayDensity(int displayId);
}

该应用程序需要位于系统应用程序文件夹中。
它确实起到了一些作用,但现在它也导致了严重的错误。
重新启动似乎会取消更改。

正在等待对此的反馈。

Searching too a valid answer to this, but I have a lead to the solution :
WARNING Experimental buggy stuff :

/*
Requires android.permission.WRITE_SETTINGS
and android.permission.WRITE_SECURE_SETTINGS, thus it requires the app to be a system app.
 */
public void changeResolution(int x, int y){
    try { Class c = Class.forName("android.os.ServiceManager");
        try { Method method = c.getDeclaredMethod("checkService", String.class);
            try {
                IWindowManager mWindowManager = IWindowManager.Stub.asInterface((IBinder) method.invoke(null,Context.WINDOW_SERVICE));
                try { mWindowManager.setForcedDisplaySize(Display.DEFAULT_DISPLAY,x,y);
                } catch (RemoteException e) {e.printStackTrace();}
            }  catch (IllegalAccessException e) {e.printStackTrace();}
            catch (InvocationTargetException e) {e.printStackTrace();}
        } catch (NoSuchMethodException e) {e.printStackTrace();}
    } catch (ClassNotFoundException e) {e.printStackTrace();}
}

Add a reduced AIDL version of IWindowManager to your project :
/app/src/main/aidl/android/view/IWindowManager.aidl

package android.view;
interface IWindowManager
{
    boolean startViewServer(int port);   // Transaction #1
    boolean stopViewServer();            // Transaction #2
    boolean isViewServerRunning();       // Transaction #3

    void setForcedDisplaySize(int displayId, int width, int height);
    void clearForcedDisplaySize(int displayId);
    void setForcedDisplayDensity(int displayId, int density);
    void clearForcedDisplayDensity(int displayId);
}

The app will require to be in the system apps folder.
It does something for sure, but right now it also lead to severe bugs.
Rebooting seems to cancel changes.

Waiting for feedback on this.

灼疼热情 2024-10-18 11:18:36

如果您使用 Windows 并且知道如何使用 JNI,Microsoft 提供了 C++ Win32 函数调用来执行此操作: ChangeDisplaySettingsEx()EnumDisplaySettings()

If you are using Windows and know how to use JNI, Microsoft provides C++ Win32 function calls to do this: ChangeDisplaySettingsEx() and EnumDisplaySettings().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文