May 6, 2008

(Android) How to change the screen orientation throw code


android.view.IWindowManager windowService = android.view.IWindowManager.Stub.asInterface(
android.os.ServiceManager.getService("window"));

try
{
if (windowService.getOrientation() == 0) //Orientation vertical
{
windowService.setOrientation(1); //Orientation horizontal
Log.i("info", "orientation 1 "+windowService.getOrientation());
}
else
{
Log.i("info", "orientation 0 "+windowService.getOrientation());
}
}
catch (DeadObjectException e)
{
e.printStackTrace();
}

No comments: