1

I wrote android service that change the device whole orientation

so home page orientation changed

this is the code

WindowManager wm = (WindowManager) getSystemService(Service.WINDOW_SERVICE);

    LinearLayout orientationChanger = new LinearLayout(this);
    orientationChanger.setClickable(false);
    orientationChanger.setFocusable(false);
    orientationChanger.setFocusableInTouchMode(false);
    orientationChanger.setLongClickable(false);

    LayoutParams orientationLayout = new WindowManager.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0,
            WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
                    | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
            PixelFormat.RGBA_8888);

    wm.addView(orientationChanger, orientationLayout);
    orientationChanger.setVisibility(View.GONE);

    orientationLayout.screenOrientation = x;
    wm.updateViewLayout(orientationChanger, orientationLayout);
    orientationChanger.setVisibility(View.VISIBLE);</i>

I want my service change the orientation but not the home page and application page

or How to write anther code that return to default device orientation

Aleks G
  • 56,435
  • 29
  • 168
  • 265

1 Answers1

-1

You can just use the code:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); or setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

to change the orientation, run either one in each activity you want changed.

ElectronicGeek
  • 3,312
  • 2
  • 23
  • 35
  • But I build Input method that just tack the orientation of the application that has text area and this not work because there is no activity in my code – user3098687 Mar 18 '14 at 16:33
  • So there's no activity, and you want to change the orientation of what? – ElectronicGeek Mar 18 '14 at 16:33
  • I don't think that's possible. You'd need to get a reference to the activity that's currently running. See this here: http://stackoverflow.com/questions/3873659/android-how-can-i-get-the-current-foreground-activity-from-a-service – ElectronicGeek Mar 18 '14 at 16:36
  • Yes I know that I can't change the orientation of IME but the code I use change the device orientation this is helpful for me but the problem now how to return the default orientation of the device – user3098687 Mar 18 '14 at 16:41
  • That was a typo, did you try running the code again? If all it does is reverse the orientation, running it again would work. – ElectronicGeek Mar 18 '14 at 16:51
  • No in the code I force it to be in landscape so it will not reverse I also try to take the orientation of the sensor it work but home page by default has portrait but after run the service it tack both portrait and landscape and this what i want to solve – user3098687 Mar 18 '14 at 16:58
  • Why can't you do what you did in the code, but just force it to become portrait? – ElectronicGeek Mar 18 '14 at 17:10
  • I want just to force home page to become portrait not all application – user3098687 Mar 18 '14 at 17:14
  • I'm not sure if its possible to force another activity/app to change their orientation, but if there is, I don't know how to do it. – ElectronicGeek Mar 18 '14 at 17:27