转自:http://whithin.blog.51cto.com/690417/1066779/
通过修改数据库System settings 来修改手机屏幕的旋转方向, 设置Settings.System. ACCELEROMETER_ROTATION和Settings.System. USER_ROTATION的值,可以通过命令行和Java API来实现
1.通过命令行来修改
su
sqlite3 /data/data/com.android.providers.settings/databases/settings.db
insert into system (name,value) values('accelerometer_rotation',0);
insert into system (name,value) values('user_rotation',1);
.exit
其中,user_rotation的值和旋转角度的关系如下,
user_rotation 0 -> ROTATION_0
user_rotation 1 -> ROTATION_180
user_rotation 2 -> ROTATION_270
user_rotation 3 -> ROTATION_90
2.通过java 程序实现
首先取消手机的重力感应
public void disableAccelerometerRotation(){
try {
Settings.System.putInt(mcontext.getContentResolver(),Settings.System. ACCELEROMETER_ROTATION,0);
} catch (Exception e) {
e.printStackTrace();
}
}
设置指定的屏幕旋转方向
public void setScreenRotation(String rotationStr){
int rotation = 0;// Surface.ROTATION_90;
if(rotationStr.equals("0" )){
rotation = Surface. ROTATION_0;
} else if (rotationStr.equals("90")){
rotation = Surface. ROTATION_90;
} else if (rotationStr.equals("180")){
rotation = Surface. ROTATION_180;
} else if (rotationStr.equals("270")){
rotation = Surface. ROTATION_270;
}
Settings.System. putInt(mcontext.getContentResolver(),Settings.System. USER_ROTATION,rotation);
}