336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
onConfigurationChanged 이벤트가 발생하기 위해서는 AndroidManifest.xml에 아래의 작업을 해준 후
사용할 Activity에 해당 이벤트를 오버라이딩하면 된다.


[AndroidManifest.xml]

targetSdkVersion을 minSdkVersion과 일치시키지 않으니 이벤트가 발생하지 않았다.

<uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="8" />

configChanges에 orientation이벤트를 사용할 것을 지정한다.

<activity
        android:name=".OrientationActivity"
        android:label="@string/title_activity_orientation"
        android:configChanges="orientation" >
</activity>


[OrientationActivity.java]

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    // Checks the orientation of the screen
    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
        Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
    } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
        Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
    }

}

출처 : http://stackoverflow.com/questions/18321680/how-to-detect-when-the-device-switch-from-portrait-to-landscape-mode

 

 

추가) 2015-07-16

portrait나 landscape 만으로 처리가 되지 않고 휴대폰 회전 각도까지도 구해야 하는 경우가 있다.

public static int getRotation(Context context) {
    Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    int degree = 0;
    int screenOrientation = display.getRotation();

    switch(screenOrientation) {
        case 0:
            degree = 0;
            break;

        case 3:
            degree = 90;
            break;

        case 1:
            degree = 270;
            break;
    }

    return degree;
}
 

'-- Android' 카테고리의 다른 글

PiXEL to DP, DP to PIXEL  (0) 2015.07.16
안드로이드 기본 인텐트 사용  (0) 2015.07.14
앱 단축아이콘과 웹사이트 단축아이콘 생성  (0) 2015.05.14
Action bar on devices before API 3.0  (0) 2014.11.25
AndroidManifest.xml  (0) 2014.09.22
posted by 어린왕자악꿍