Android5.1 禁止屏幕随app旋转
求教大神。目前用同一个app,分别装在Android手机和RK3288开发板上。在开发板上打开app时,屏幕会变为横屏,而在Android手机上则不会,想一直让屏幕处于竖屏模式下。请问如何禁止屏幕旋转。 这个so easy 我就不公布答案了,百度一大把 修改文件:
WindowManagerService.java (frameworks\base\services\core\java\com\android\server\wm)
中,函数
boolean updateOrientationFromAppTokensLocked(boolean inTransaction) {
long ident = Binder.clearCallingIdentity();
try {
//int req = getOrientationFromWindowsLocked();//屏蔽原有代码
//写死req变量,可以通过用property,来灵活设置强制或自动旋转
int req = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
req = getOrientationFromAppTokensLocked();
}
if (req != mForcedAppOrientation) {
mForcedAppOrientation = req;
//send a message to Policy indicating orientation change to take
//action like disabling/enabling sensors etc.,
mPolicy.setCurrentOrientationLw(req);
if (updateRotationUncheckedLocked(inTransaction)) {
// changed
return true;
}
}
return false;
} finally {
Binder.restoreCallingIdentity(ident);
}
} buzaiyouyu001 发表于 2016-12-14 14:32
修改文件:
WindowManagerService.java (frameworks\base\services\core\java\com\android\server\wm ...
最优解!
页:
[1]