2016-11-29 1 views
0

장치를 가로/세로 모드로 강제 잠금하는 데 문제가 있습니까?Android : 전체 안드로이드 장치를 가로 방향 또는 세로 방향으로 강제 실행하는 방법

내 장비가 가로 전용 기기 였기 때문에 활동 자체에 화면 방향이 가로로 지정되는 런처 앱을 만들었습니다.

선택한 다른 응용 프로그램이 가로 화면에서 실행될 때 화면을 잠그는 데 도움이됩니다.

View orientationChanger = new LinearLayout(this); 
    WindowManager.LayoutParams orientationLayout = new WindowManager.LayoutParams(WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, 0, PixelFormat.RGBA_8888); 
    orientationLayout.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR; 

    WindowManager wm = (WindowManager) this.getSystemService(Service.WINDOW_SERVICE); 
    wm.addView(orientationChanger, orientationLayout); 
    orientationChanger.setVisibility(View.VISIBLE); 

트릭을 수행합니다.

이제 세로 모드로 실행해야하는 일부 응용 프로그램의 경우 사용자가 방향을 회전 할 수있게하려고합니다.

I tried to run these command on adb shell before doing it on my code: 

try { 
     Process stopAccelerometer = Runtime.getRuntime().exec("content insert --uri content://settings/system --bind name:s:accelerometer_rotation --bind value:i:0"); 
     Process toProtrait = Runtime.getRuntime().exec("content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:3"); 
    } catch (IOException ex) { 
     ex.printStackTrace(); 
    } 

예 응용 프로그램을 세로로 실행하지만 가로로 돌아가려면 명령을 적용하면 다시 가로로 돌아갑니다.

  Process toProtrait = Runtime.getRuntime().exec("content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:0"); 

코드에서 마지막 값은 landscape로 0입니다. 나는 응용 프로그램 자체가 풍경을 지원하지 않는다고 생각합니다. 그래서 명령을 적용했을 때 응용 프로그램은 Portrait에 머물렀습니다.

나는 그 일을 온라인으로하는 응용 프로그램을 발견했습니다. Orientation Applications

답변

0

요청 가로 모드로 활동

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); 
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 

요청

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); 
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 

이 한 OnCreate에 넣어 세로 모드로 활동();

하거나이 매니페스트 활동

<activity 
    android:screenOrientation="portrait/landscape" 
    android:name=".ui.MainActivity" 
    android:windowSoftInputMode="stateHidden"/> 
+0

내가 screenOrientation에 슬래시를 가질 수 없습니다에 설정합니다. 하나의 옵션 만 허용합니다. – LittleFunny

+0

옙 .. 그것의 단지 옵션 potrait 또는 풍경 .. 하나를 선택하십시오 .. – ZeroOne

관련 문제