Android examples for Phone:Screen
lock Current Screen Orientation
import android.annotation.SuppressLint; import android.app.Activity; import android.content.res.Configuration; import android.content.res.Resources; import android.os.Build.VERSION; import android.view.Display; import android.view.Window; import android.view.WindowManager; import android.view.WindowManager.LayoutParams; import java.lang.reflect.Method; public class Main{ public static void lockCurrentScreenOrientation(Activity paramActivity) { Configuration localConfiguration = paramActivity.getResources() .getConfiguration();// www .j a v a2s. c o m Display localDisplay = paramActivity.getWindowManager() .getDefaultDisplay(); if (localConfiguration.orientation == 2) switch (localDisplay.getRotation()) { default: paramActivity.setRequestedOrientation(0); case 2: case 3: } do { return; paramActivity.setRequestedOrientation(8); return; } while (localConfiguration.orientation != 1); switch (localDisplay.getRotation()) { default: paramActivity.setRequestedOrientation(1); return; case 1: case 2: } paramActivity.setRequestedOrientation(9); } }