根据系统是否支持自动旋转设置屏幕方向


@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    boolean autoRotateOn = (android.provider.Settings.System.getInt(getContentResolver(),Settings.System.ACCELEROMETER_ROTATION, 0) == 1) ;
    if(autoRotateOn){
      Log.i("onResume", "可以自动旋转");
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
    }else{
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER);
      Log.i("onResume", "不可以自动旋转 用户首选");
    }
}

原文地址:https://www.cnblogs.com/lucktian/p/5519654.html