How check status of Phone is Landscape or Portrait when Ativity not auto rotation?
android
Solution
Try this..
`getResources().getConfiguration()` will return `Configuration`
if(YourActivity.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)
{
// Portrait Mode
} else {
// Landscape Mode
}
EDIT
Get phone orientation when locked into one orientation
Problem
Ativity not auto rotation: ``` <activity android:name=".E028" android:label="@string/app_name" android:screenOrientation="portrait" android:theme="@android:style/Theme.Black.NoTitleBar" > </activity> ``` If i use onConfigurationChanged , it not working: ``` @Override public void onConfigurationChanged(Configuration newConfig) { // TODO Auto-generated method stub super.onConfigurationChanged(newConfig); 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(); } } ``` How check status of Phone is Landscape or Portrait when Ativity not auto rotation? I think this case: i must use sensor My code: ``` @Override public void onSensorChanged(SensorEvent event) { // TODO Auto-generated method stub if (event.values[1] < 6.5 && event.values[1] > -6.5) { if (orientation != 1) { Log.d("Sensor", "Landscape"); // listImage.notifyDataSetChanged(); } orientation = 1; } else { if (orientation != 0) { Log.d("Sensor", "Portrait"); // listImage.notifyDataSetChanged(); } orientation = 0; } } ``` But it working not best,Status of my phone is Portrait: If inclined a little back , value return is Landscape.