Auto Rotate for the Android Browser

I'm not sure why the Android Browser doesn't auto rotate by default. Instead they have a "Flip Orientation" menu item that lets you toggle your default orientation. Pretty useless overall. Anyhow, a quick hack in the Browser source code let me enable auto rotation via the G-Sensor.

The change is really trivial. In the BrowserActivity.onCreate, I hard coded the orientation to ActivityInfo.SCREEN_ORIENTATION_SENSOR instead of pulling it from a preferences setting.

The downside is that the flip orientation menu item no longer works. Not that I care: I (and probably most people) never used it. So it is a hack, but oh well. If I'm motivated I'll put in a proper fix.

Installation Instructions (you must have root access):

  • Download the updated Browser.apk
  • Run the following from the command prompt to back up your current Browser file to your sdcard and install the new one:
    • adb remount
    • adb pull /system/app/Browser.apk BrowserBackup.apk
    • adb push BrowserBackup.apk /sdcard
    • adb shell rm /system/app/Browser.odex
    • adb push Browser.apk /system/app

16 comments:

Anonymous said...

can you recompile it so we can use the new broswer with those of us who dont have root? thanks!

Unknown said...

i installed the browser.apk via my phone so i don't know what that did. the screen slid left then right again (using droidsan tweaklite)

so i get down to the step where i have to enter:

adb push BrowserBackup.apk /sdcard

I then get the message (on the cmd on computer):

cannot stat 'BrowserBackup.apk' : no such file or directory

did i mess up when i tried to open it on my phone before?

any help Koush?

Unknown said...

i dont think you're supposed to install it.
just downloaded and save it to your '\tools' folder in you 'SDK' folder and then follow the instructions
adb remount
adb pull /system/app/Browser.apk BrowserBackup.apk
adb push BrowserBackup.apk /sdcard
adb shell rm /system/app/Browser.odex
adb push Browser.apk /system/app

then open the browser.

this did it for me.

H said...

Works like a charm Thanks !!!!

Anonymous said...

I got an error message while copying the backup file to the sdcard. error was something like this " Failed to copy BrowserBackup.apk to /sdcard/BrowserBakcup.apk' : Read-only file system"

How do i set a permission to write for this device?

Unknown said...

Koushik -- you say to remove a .odex file, and instead you mean "adb shell rm /system/app/Browser.apk"

Also at least on my development phone adb remount and so on give permission denied and the paths are different.

So instead, I had to shell to the phone first, su to root and create a tmp directory that could be written to by adb.

Bamba1260 said...

I am use telnet for my cmd but when i enter adb, it says not found. help please?

Anonymous said...

it always said adb not found

Anonymous said...

so do we use the emulator or telnet to type adb? because when i use the emulator it says permission denied for adb.

Stb said...

how did you recompile just the one app???

califrag said...

Since this is the first page that comes up when you search google for 'android browser auto rotate' i thought it's worth mentioning that if you click 'menu' in the browser, then go to 'settings' there is an 'Enable auto-rotate' feature. I'm not sure if this is newly added with the RC33 I have installed, or if it's something added cause I rooted my phone and got JF RC33 but figured it's worth mentioning.

Anonymous said...

Sorry, a complete novice here...

After installing the new browser.apk file to the sdcard. From where exactly do I run those commands?

Anonymous said...

I just posted the post above but then actually took the time to read the posts that already exist...

..and found that my browser settings also has the settings to auto rotate as bensaraceno mentioned. I'm on RC9

Alex said...

People, you need to have root access to do this. If you have root access you should have "Terminal Emulator" in your applications. Run this, and then type "su". Su should override the system and allow you to run commands. After this you should be able to do adb, etc. etc.

My problem is that when I run "adb remount" or "adb whatever" it always says "adb: not found". Any help?

Anonymous said...

MyBrainHurts,

Thank you so much for making this available. I suspect JF got the application from you. On the other hand, maybe you should update the post to reflect what bensaraceno@gmail.com mentioned.

Many users who have root are also going to have a JF build and thus might actually set themselves back by adding the modified browser (and certainly be wasting their time).

Tony said...
This comment has been removed by the author.