I want to restricted orientation auto change in my application.means screen always be portrait when mobile will landscape or portrait..orientation will never be change.
How can I do this. Plz help me.
thankyou
I want to restricted orientation auto change in my application.means screen always be portrait when mobile will landscape or portrait..orientation will never be change.
How can I do this. Plz help me.
thankyou
This is the right way to do it.
<activity android:name=".SomeActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
Add `android:configChanges=orientation' to your AndroidManifest.xml file. It will tell Android that you will handle the orientation change. If you want to use only portrait, you will do nothing when the orientation changed to landscape.
<activity android:name="MainActivity" android:configChanges="orientation">
This line of code sets the screen orientation to your device default in the current Activity and prevents it from changing.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//.....
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
//.....
}
Use ActivityInfo.... for any other options you want.
Enjoy!
Add android:screenOrientation="portrait" to the element in the manifest or landscape