android 7.0 关闭系统自动旋转
来源:互联网 发布:重庆大学软件工程学院 编辑:程序博客网 时间:2024/05/22 13:35
实现效果:编译开机,屏幕不会随着机器旋转而旋转
方法一:(成功)
1、点击界面 DisplaySettings.java
下面这段代码就是为了显示出setting 里面 旋转按钮的点击界面
if (RotationPolicy.isRotationLockToggleVisible(activity)) { DropDownPreference rotatePreference = (DropDownPreference) findPreference(KEY_AUTO_ROTATE); int rotateLockedResourceId; // The following block sets the string used when rotation is locked. // If the device locks specifically to portrait or landscape (rather than current // rotation), then we use a different string to include this information. if (allowAllRotations(activity)) { rotateLockedResourceId = R.string.display_auto_rotate_stay_in_current; } else { if (RotationPolicy.getRotationLockOrientation(activity) == Configuration.ORIENTATION_PORTRAIT) { rotateLockedResourceId = R.string.display_auto_rotate_stay_in_portrait; } else { rotateLockedResourceId = R.string.display_auto_rotate_stay_in_landscape; } } rotatePreference.setEntries(new CharSequence[] { activity.getString(R.string.display_auto_rotate_rotate), activity.getString(rotateLockedResourceId), }); rotatePreference.setEntryValues(new CharSequence[] { "0", "1" }); rotatePreference.setValueIndex(RotationPolicy.isRotationLocked(activity) ? 1 : 0); rotatePreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { final boolean locked = Integer.parseInt((String) newValue) != 0; MetricsLogger.action(getActivity(), MetricsEvent.ACTION_ROTATION_LOCK, locked); RotationPolicy.setRotationLock(activity, locked); return true; } }); } else { removePreference(KEY_AUTO_ROTATE); }
2、跳转到 RotationPolicy.java (修改文件)
/** * Returns true if rotation lock is enabled. */ public static boolean isRotationLocked(Context context) { return Settings.System.getIntForUser(context.getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) == 0; }
将这个代码修改为:
/** * Returns true if rotation lock is enabled. */ public static boolean isRotationLocked(Context context) { setRotationLock(true, NATURAL_ROTATION); return true; }
就是在它作出判断书不是自动旋转的时候,让它跳转到锁定自动旋转函数
private static void setRotationLock(final boolean enabled, final int rotation) { AsyncTask.execute(new Runnable() { @Override public void run() { try { IWindowManager wm = WindowManagerGlobal.getWindowManagerService(); if (enabled) { Log.w(TAG, "lum_1 rotation is :" + rotation); wm.freezeRotation(rotation); (禁止自动旋转) } else { Log.w(TAG, "lum_2 rotation is " + rotation); wm.thawRotation(); (可以自动旋转) } } catch (RemoteException exc) { Log.w(TAG, "Unable to save auto-rotate setting"); } } }); }
将自动旋转注销即可。
修改为:
private static void setRotationLock(final boolean enabled, final int rotation) { AsyncTask.execute(new Runnable() { @Override public void run() { try { IWindowManager wm = WindowManagerGlobal.getWindowManagerService(); wm.freezeRotation(rotation); } catch (RemoteException exc) { Log.w(TAG, "Unable to save auto-rotate setting"); } } }); }
方法2 :(没成功)
frameworks/base/cmds/screencap/screencap.cpp
修改:
uint8_t displayOrientation = configs[activeConfig].orientation; + displayOrientation = ISurfaceComposer::eRotateNone; uint32_t captureOrientation = ORIENTATION_MAP[displayOrientation];
文献参考:
辅助设置中自动旋转
http://blog.csdn.net/wangxueming/article/details/43969341
强制系统横屏竖屏
http://blog.csdn.net/kongbaidepao/article/details/54427625
Android6.0 旋转屏幕(四)应用强制设置方向
http://blog.csdn.net/kc58236582/article/details/53741445
关于 Android 4.4 系统屏幕旋转调研 (推荐)
http://blog.csdn.net/jangel_lee/article/details/44949155
android如何改变系统默认横竖屏方向
http://blog.csdn.net/wh_19910525/article/details/37963375
阅读全文
0 0
- android 7.0 关闭系统自动旋转
- android怎样实现关闭系统自动旋转屏幕时能够自动横竖屏
- iOS UIViewController 无法关闭自动旋屏(自动旋转、手动旋转、兼容IOS6之前系统)
- Android调用系统 拍照 相册 适配所有版本 7.0 恢复自动旋转
- 解决一部分android手机照片被系统自动旋转
- 关闭系统自动共享
- android dialog自动关闭
- android dialog自动关闭
- 系统每天自动关闭设置
- 开户自动旋转在某应用中横屏后关闭自动旋转,该应用不会自动恢复到竖屏,
- android自动旋转简单分析
- android自动旋转简单分析
- Android Sensor 自动旋转控制
- XP系统自动登录,关闭自动播放
- 关闭android系统自动更新
- android系统 关闭应用
- android 系统数据业务---关闭
- Android系统实现横竖屏两方向自动旋转的方法
- 10-面向对象
- Linux信号机制之sigaction结构体浅析
- SpringBoot(1)
- C语言一周学习内容总结
- 【ccf 201709-2】公共钥匙盒
- android 7.0 关闭系统自动旋转
- C++ 图的实现
- 阿里云CentOS7中安装Maven3.5
- redis主从服务器
- 【20171014】python_语言设计(8)面向对象程序设计
- 利用#pragma execution_character_set("utf-8")解决QT中显示中文字乱码
- java 多线程 方法2 使用Runnable接口
- 方法区
- AB1601 IO口反应延时的问题