Im adding a camera overlay with WindowManager to a running Activity. When I start the camera and call for the WindowManager, it changes my screen from portrait to landscape, even though I assigned the appropriate portrait tag to the WindowManager.LayoutParams. Haven't been able to find any solutions via google.
Here is my WindowManager code running in a method in a service:
inflater = (LayoutInflater) mContext.getSystemService(mContext.LAYOUT_INFLATER_SERVICE);
windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
View view;
view = inflater.inflate(R.layout.camera, null, false);
p = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT);
p.gravity = Gravity.TOP | Gravity.CENTER;
p.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
windowManager.addView(view,p);
The layout R.layout.camera is just a FrameLayout view that I add my camera to. Camera is working fine. My activity running underneath is portrait (As it should be) until the WindowManager instance turns it back to landscape. And yes, I have the portrait tag in my Manifest.
Edit: With further investigation, the windowmanager is destroying and recreating my activity running, and this is causing everything to revert to landscape mode. I even tried setting the orientation dynamically in the onCreate of the Activity, but that did not work either. When I stop the service with all of the above windowmanager code, my activity goes back to portrait mode.