1

I am creating an application which will change the orientation of some other already installed application, Reading the orientation of other application installed was simple through ApplicationInfo object but no way to change it.

After some R&D I have come to notice similar types of apps (which change orientation) also run Service, that means they make orientation change on fly but I don't know how exactly they do it.

For example like Smart Rotator app does it https://play.google.com/store/apps/details?id=net.xdevelop.rotator_t&hl=en

6
  • is this helpful ? - developer.samsung.com/android/technical-docs/… Commented Jan 28, 2013 at 18:04
  • You mean screen orientation right? Commented Jan 29, 2013 at 8:08
  • @Alpay yes want to change screen orientation of other application. Commented Jan 29, 2013 at 8:54
  • @Ty221 I want to control screen orientation of another app not mine. Commented Jan 29, 2013 at 8:55
  • 1
    @Alesqui play.google.com/store/apps/… Commented Jan 31, 2013 at 2:29

2 Answers 2

2
+50

The other apps that you reference do something different to what you might be expecting. They enable screen rotation based on the device's accelerometer; that is, the user rotates the device and the orientation changes. They do not set a specific orientation for any application. Note that if you disable automatic rotation whilst in landscape mode, the orientation typically returns to portrait.

I have done the same as these other applications before. Unfortunately it's proprietary commercial code that I'm not in a position to share.

There are two components to the approach:

  1. Detect when the foreground application is the target app
  2. Change the system-wide preference for display orientation

Obviously you have to do the reverse too, i.e. change it back afterwards.

There are some examples of piece 1 elsewhere on SO. In my case I wrote a service that continuously polled to see what the foreground app is (because there are no relevant system events to inform of app change). It's not a trivial undertaking but it can be done.

The relevant setting for piece 2 is Settings.System.ACCELEROMETER_ROTATION. I think you can write that with an ordinary app permission on all versions. The code snippet for that is below:

 Settings.System.putInt( app.getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, orientationEnabled ? 1 : 0 ); 

Note also that it is possible to write an application that will ignore the system's screen rotation; i.e. will stay locked in whatever orientation it was designed for. It's not common though.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks for your answer , can you provide pseudo code for piece 1 aswell i.e polling to check app running and end status ?
Not as such, but this looks like a reasonable starting point. In practice you will find there are various subtleties; as one example, applications that are invoked to handle a broadcast but do not visually appear are treated as being in the foreground - but that's the sort of thing you should probably address with a new SO question when you encounter it.
1

You can do this by interprocess communication. You have several options:

1- You can use SharedPreferences. Set a WORLD_READABLE preference from your application to be read on every startup from your target application. Have a look at this.

2- You can write this preference in a file on sdcard and read it in the same way.

3- If your target application is running (that is, it has a Service or something else so its process is alive) you can broadcast an intent and receive it from your target application. Here you can find a post about this subject.

4- ... In short you need to pass a parameter to your target application and set your orientation as in setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

3 Comments

The app whose orientation I would like to change is not my application
The applications on Android devices are all reside in their seperate sandboxes. Unless both the changing and the changer application is yours and you design them in a special way I mentioned above, It will and should be impossible to change another application' s properties, like screen orientation. Would you want some irrelevant application to change your application' s properties without your permission?
it might look impossible but here is an app which does it play.google.com/store/apps/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.