0

I want to lock screen to landscape or patriot mode for all apps on my Android device. What should I do beside disable auto screen orientation?

I have check out some apps from android market and try to see what they do. It seems those apps create an service to manipulate WindowManager like this.

WindowManager wm = (WindowManager)getSystemService(CONTEXT.WINDOW_SERVICE);
CustomLayout cl = new CustomLayout(desire_orientation);
View localView = new View(this);
wm.addView(localView, cl);

But when I fail to do something like this. Any idea?

Also, I am able to change framework code, from Java to C++, any other way to do this?

David Guan
  • 809
  • 1
  • 8
  • 13
  • You can try this [link ][1] [1]: http://stackoverflow.com/questions/5112118/how-to-detect-orientation-of-android-device – Newts Feb 16 '12 at 07:17
  • 1
    Potentially locking other apps' functionality doesn't sound like something the Android platform would allow. I could be wrong though! – Nick Badal Feb 16 '12 at 07:20

1 Answers1

0
WindowManager.LayoutParams params = new WindowManager.LayoutParams();
params.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
wm.addView(localView, params);

this works for me.

Tsung Wu
  • 1,064
  • 9
  • 17
  • Thankyou that was useful ! but now i have a problem ,when i rotate phone in portrait mode then close the window it will be appear again – Smile Apr 05 '14 at 17:46