【RK3568】Android 11强制所有应用横屏展示

本文参考自Android11 强制所有第三方应用全屏

前言

在进行Framework定制时,有时我们会内置第三方应用到系统中,因为我这里终端设备是横屏展示的,内置的部分第三方应用存在竖屏显示的情况,这种情况下使用体验不好,所以尝试通过以下方式通过系统强制所有应用横屏展示(Android 11亲测有效)。


解决方式

  • 打开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
  • 打开frameworks/base/core/java/android/app/Activity.java文件,对setRequestedOrientation方法进行如下修改:
    /**
     * Change the desired orientation of this activity.  If the activity
     * is currently in the foreground or otherwise impacting the screen
     * orientation, the screen will immediately be changed (possibly causing
     * the activity to be restarted). Otherwise, this will be used the next
     * time the activity is visible.
     *
     * @param requestedOrientation An orientation constant as used in
     * {@link ActivityInfo#screenOrientation ActivityInfo.screenOrientation}.
     */
    public void setRequestedOrientation(@ActivityInfo.ScreenOrientation int requestedOrientation) {
        if (mParent == null) {
            try {
                // Edit by jgduan
                //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);
                }
                // End
            } catch (RemoteException e) {
                // Empty
            }
        } else {
            // Edit by jgduan
            // mParent.setRequestedOrientation(requestedOrientation);
            if(mApplication != null && mApplication.getApplicationInfo() != null
                    && mApplication.getApplicationInfo().uid > 10000){
                mParent.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            }else{
                mParent.setRequestedOrientation(requestedOrientation);
            }
            // End
        }
    }
  • 重新编译,烧录后即可看到效果
    未设置强制横屏前效果

    强制横屏后效果

拓展阅读

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容