import android.content.Context;
import android.view.Surface;
import android.view.WindowManager;
// 获取当前的屏幕方向
WindowManager windowManager = context.getSystemService(Context.WINDOW_SERVICE);
int rotation = windowManager.getDefaultDisplay().getRotation();
//设置当前屏幕方向
android.provider.Settings$System.putInt(context.contentResolver, "user_rotation", rotation);
//关闭自动旋转
android.provider.Settings$System.putInt(context.contentResolver, "accelerometer_rotation", 0);