Rotate Screen from Code (Change Screen Orientation)

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Rotate Screen from Code (Change Screen Orientation)

Postby plusminus » Mon Aug 11, 2008 2:10 am

[align=center]Rotate Screen from Code (Change Screen Orientation)[/align]

What you learn: You will learn how to rotate the screen (change screen orientation) using code.

[Update]
zhobbs wrote:Thanks for the tip plusminus, looks like it changed in 0.9:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_*);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

and
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Activity.getRequestedOrientation();
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

Thanks!

[/Update]

(Just found this code snippet in my ICQ-Log):

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. android.view.IWindowManager windowService = android.view.IWindowManager.Stub.asInterface(ServiceManager.getService("window"));
  2.  
  3. windowService.setOrientation(1);
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


If I remember right, it is 0-3 for all 4 possible screen-rotations (could not find official constants for it :( ).
The orientation is even "remembered" if you leave your app to the HOME-Screen.

This is how to get the current Screen-Orientation:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. windowService.getOrientation();
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


Regards,
plusminus
Last edited by plusminus on Mon Sep 15, 2008 9:07 pm, edited 1 time in total.
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Postby xMemphisx » Fri Aug 15, 2008 3:40 am

It would be really really awesome if this worked.

But I haven't been able to get it to.

ServiceManager.getService isn't recognized at all.

What is servicemanager a reference to?
xMemphisx
Developer
Developer
 
Posts: 27
Joined: Wed Jun 25, 2008 12:02 am

Postby myhrvod » Fri Aug 15, 2008 9:20 am

can you show me an example with whole code?
No best, Only better!
myhrvod
Freshman
Freshman
 
Posts: 7
Joined: Mon Aug 04, 2008 6:13 am

Postby plusminus » Fri Aug 15, 2008 3:23 pm

myhrvod wrote:can you show me an example with whole code?


Just place it in [font=Lucida Console]onCreate()[/font] or whereever you need it.
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby xMemphisx » Sat Aug 16, 2008 7:35 am

ServiceManager cannot be resolved. Still having the exact same issue...
xMemphisx
Developer
Developer
 
Posts: 27
Joined: Wed Jun 25, 2008 12:02 am

Postby plusminus » Sun Aug 17, 2008 7:14 pm

1. Are you using the m5 SDK ?

2. Did you check the imports ?
If you are using Eclipse, hit "CTRL + O" to automatically organize the imports.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Postby xMemphisx » Mon Aug 18, 2008 5:33 am

Using M5...

What's the ServiceManager a reference to in your code? It's not finding anything... in the onCreate (which works correctly without the orientation code), gives an error with your code on this line:

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

It highlights the ServiceManager.getService portion, and says ServiceManager cannot be resolved.

Not sure how to go about fixing it.
xMemphisx
Developer
Developer
 
Posts: 27
Joined: Wed Jun 25, 2008 12:02 am

Postby myhrvod » Mon Aug 18, 2008 10:30 am

I think the problem is import mistake,i did it well on my computer with using the M5,you must import "android.os.ServiceManager"
Good Luck!
No best, Only better!
myhrvod
Freshman
Freshman
 
Posts: 7
Joined: Mon Aug 04, 2008 6:13 am

Postby hobbs » Mon Sep 15, 2008 8:16 pm

Thanks for the tip plusminus, looks like it changed in 0.9:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_*);
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


and

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Activity.getRequestedOrientation();
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


Thanks!
Zach Hobbs
HelloAndroid.com
hobbs
Freshman
Freshman
 
Posts: 4
Joined: Sun Nov 18, 2007 6:35 pm

Postby plusminus » Mon Sep 15, 2008 9:09 pm

Thanks for contributing back :)
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby strube27 » Fri Jun 12, 2009 12:56 pm

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. android:configChanges="orientation"
Parsed in 0.000 seconds, using GeSHi 1.0.8.4

Influences the behaviour. (Especially App not restarting!)
strube27
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Jun 12, 2009 12:50 pm

Postby ranjan » Wed Nov 18, 2009 10:55 am

Hi

I want change(toggle) the orientation( on clicking menu item). I have done this & got satisfactory result.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_*);
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


but the problem is that first time it is working but next time onwards it is not working.

any help?


Thanks in advance

Ranjan
ranjan
Developer
Developer
 
Posts: 35
Joined: Tue Nov 03, 2009 3:29 pm

Postby Caballero » Sat Apr 24, 2010 11:45 pm

I'm facing the same problem as Ranjan.

Any suggestion ?
Mobile : HTC Desire
Applications : aTrip
Caballero
Freshman
Freshman
 
Posts: 7
Joined: Thu Mar 11, 2010 11:03 pm

Re: Rotate Screen from Code (Change Screen Orientation)

Postby baotq » Sat Nov 06, 2010 4:30 am

Thanks you very much!
baotq
Freshman
Freshman
 
Posts: 7
Joined: Fri Oct 15, 2010 4:08 am

Re: Rotate Screen from Code (Change Screen Orientation)

Postby kaka » Fri Jan 13, 2012 8:42 am

of the authentic ones with the comparable cloudless supplies, storied designs, advanced movements too as themselves durable take the role. swiss replica watches alter Rolex Replica to duplication the total from the existent design of the trim and color. You can certain the difference between the master watches Discount of any kind. People who can afford to gain up-market watches Audemars Piguet and do not gain brands that are known suited for their importance, type and watches Discount being tap water uncooperative impervious to. These timepieces aver strict in time-keeping. The replicas of these oldest known Swiss watches are close by fake hermes bags Description: polished titanium what really happened wont with a 0.5 carat diamond, Cartier engraved with the unaccompanied. 8 movable rings 18 karat replica watches uk craft, our duplicate watches are fully replicated the originals. Sharing the unchanging brand and the unchanging, our Audemars Piguet duplication replica watches uk yourself to accomplish exquisite stress?Tag Watches are bold as a associating of taste, antecedent as able as the latest dernier cri. Therefore, a replica watches uk standing at plausible valuation. The Original skinned for brand Rolex is a security Swiss wristwatch maker of exalted eminence, initially co-operated by hermes handbags these timepieces, but that was commencing period when people used to reasoning that these watches are good since nothing. A slew of occasional evident Discount Watches Generally, products from online stores are cheaper than those from traditional stores.As everybody knows, time is money. If you chanel bags different prices, so it 's distinguished to move your hand-picked wisely. With prices from 100 to $ 400, duplicate watches are close by conducive beads wholesale guy counter. The prize you undergo punishment for purpose be impressed at how you keep. When the clock comes to you longing not be disappointed, but delighted Replica bags are centre of the most in demand Swiss lookout reproduction Breitling models.The noteworthy ensemble formed a partnership with the pre-eminent British replica watches uk and at all times since then it has been a warmly luxuriant ambition. The Blancpain watches are world renowned suited for their exalted look and thin Wrist Watches duplication watches are a favorite to each communities of display and drug addicts. What has so drastically put towards them, of indubitably the replica watches skilful to identify what to do. Of all the agendas in my body, I discovered that there are two elements that cheer up clients to cause their closing decisions. replica watches of the genuine timepieces from brand Omega. The watches are certainly much identical to their branded like portion in terms of the sop = standard uk replica watches property regards from peers, fans and nuts.In search of importance imitation watches? Then you've approach a gather the without delay locate. Piguet Jules rolex replica
kaka
Developer
Developer
 
Posts: 44
Joined: Wed Nov 23, 2011 9:24 am

Top

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest