Controlling the camera to take pictures in portrait doesn’t rotate the final images

The problem is when I saved the image I didn’t do well. @Override public void onPictureTaken(byte[] data, Camera camera) { String timeStamp = new SimpleDateFormat( “yyyyMMdd_HHmmss”).format( new Date( )); output_file_name = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + File.separator + timeStamp + “.jpeg”; File pictureFile = new File(output_file_name); if (pictureFile.exists()) { pictureFile.delete(); } try { FileOutputStream fos = new FileOutputStream(pictureFile); … Read more

Force an Android activity to always use landscape mode

Looking at the AndroidManifest.xml (link), on line 9: <activity android:screenOrientation=”landscape” android:configChanges=”orientation|keyboardHidden” android:name=”VncCanvasActivity”> This line specifies the screenOrientation as landscape, but author goes further in overriding any screen orientation changes with configChanges=”orientation|keyboardHidden”. This points to a overridden function in VncCanvasActivity.java. If you look at VncCanvasActivity, on line 109 is the overrided function: @Override public void onConfigurationChanged(Configuration … Read more

Restoring state of TextView after screen rotation?

If you want to force your TextView to save its state you must add freezesText attribute: <TextView … android:freezesText=”true” /> From documentation on freezesText : If set, the text view will include its current complete text inside of its frozen icicle in addition to meta-data such as the current cursor position. By default this is … Read more

Android: Temporarily disable orientation changes in an Activity

As explained by Chris in his self-answer, calling setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR); and then setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); really works like charm… on real devices ! Don’t think that it’s broken when testing on the emulator, the ctrl+F11 shortcut ALWAYS change the screen orientation, without emulating sensors moves. EDIT: this was not the best possible answer. As explained in the comments, … Read more

How can I disable landscape mode in Android?

Add android:screenOrientation=”portrait” to the activity in the AndroidManifest.xml. For example: <activity android:name=”.SomeActivity” android:label=”@string/app_name” android:screenOrientation=”portrait” /> Since this has become a super-popular answer, I feel very guilty as forcing portrait is rarely the right solution to the problems it’s frequently applied to. The major caveats with forced portrait: This does not absolve you of having to … Read more

Background task, progress dialog, orientation change – is there any 100% working solution?

Step #1: Make your AsyncTask a static nested class, or an entirely separate class, just not an inner (non-static nested) class. Step #2: Have the AsyncTask hold onto the Activity via a data member, set via the constructor and a setter. Step #3: When creating the AsyncTask, supply the current Activity to the constructor. Step … Read more

How do I disable orientation change on Android?

Update April 2013: Don’t do this. It wasn’t a good idea in 2009 when I first answered the question and it really isn’t a good idea now. See this answer by hackbod for reasons: Avoid reloading activity with asynctask on orientation change in android Add android:configChanges=”keyboardHidden|orientation” to your AndroidManifest.xml. This tells the system what configuration … Read more