There are times where you need to ensure that your application is displayed only in a certain orientation. For example, suppose you are writing a game that should only be viewed in landscape mode. In this case, you can programmatically force a change in orientation using the setRequestOrientation() method of the Activity class:
package net.learn2develop.OrientationAware;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
public class Orientation extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//---change to landscape mode---
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
}
To change to portrait mode, use the ActivityInfo.SCREEN_ORIENTATION_PORTRAIT constant:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Developing Orientation-Aware Android Applications.
[...] via [SOLVED] Set Screen Orientation Programmatically « RussenReaktor’s Weblog. [...]
ReplyDeleteIs this possible from outside of an activity? So I can force an app, that's not controlled by me, to change orientation?
ReplyDeleteThanks
Tom
Just put attach a command to the Intent before it's sent, and retrieve it when the class gets instantiated.
ReplyDeleteIn the intent
intent.putExtra("orientation", "portrait");
In the class
String orientation = getIntent().getExtras().getString("orientation");
if(orientation == "portrait"){
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
} else {
// defaults to landscape
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
[...] http://russenreaktor.wordpress.com/2010/01/03/solved-set-screen-orientation-programmatically/ [...]
ReplyDelete[...] method). If it is less that 5 inch set activity orientation to portrait manually. [...]
ReplyDeleteYou can purchase a micro - SD memory stick which has two gigabytes (GB) of memory while also purchasing
ReplyDeletea memory stick Pro - Duo which only has one GB
or less of memory space. The following suggestions should be considered before buying a memory card:
a. The memory card reader is used in usb-capable pc and other devices helping the user in collecting information from
the system which is placed in the memory card reader.
you are really a just right webmaster. The site loading pace
ReplyDeleteis amazing. It seems that you are doing any unique trick. Moreover, The contents are masterpiece.
you have done a magnificent process on this subject!
You are so cool! I do not think I've read anything like this before. So nice to discover someone with some original thoughts on this topic. Seriously.. thank you for starting this up. This web site is one thing that is required on the web, someone with a bit of originality!
ReplyDeletewonderful post, very informative. I'm wondering why the opposite experts of this sector do not realize this. You must proceed your writing. I'm confident, you have a
ReplyDeletegreat readers' base already!
Hmm is anyone else having problems with the pictures on this blog
ReplyDeleteloading? I'm trying to find out if its a problem on my end or if it's the blog.
Any feedback would be greatly appreciated.