Reputation: 4327
I'm trying to rotate the screen of the user's device. So far, the code below works great on all devices I've tested except the Amazon Fire TV Stick. While the screen does rotate, any video playing in full-screen mode in apps such as YouTube, Netflix, or any streaming app remains in the default orientation, as you can see in the below picture.
The YouTube UI is rotated upsidedown but the video itself is still in the default orientation :
private WindowManager.LayoutParams mainLayoutParams;
private TextView fakeTextView;
private WindowManager windowManager;
private static final int OVERLAY_FLAGS =
FLAG_NOT_FOCUSABLE | FLAG_KEEP_SCREEN_ON | FLAG_DISMISS_KEYGUARD | FLAG_TURN_SCREEN_ON |
FLAG_SHOW_WHEN_LOCKED | FLAG_NOT_TOUCHABLE | FLAG_WATCH_OUTSIDE_TOUCH;
@Override
public void onCreate() {
super.onCreate();
LogUtils.dTag("NotificationDebug", "onCreate from notification");
createNotificationChannel();
mainLayoutParams = new WindowManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT,
(Build.VERSION.SDK_INT >= 26) ? WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY : WindowManager.LayoutParams.TYPE_PHONE,
OVERLAY_FLAGS,
PixelFormat.TRANSLUCENT);
fakeTextView = new TextView(this);
windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
WindowManager.LayoutParams layoutParams = mainLayoutParams;
layoutParams.x = 0;
layoutParams.y = 0;
layoutParams.gravity = Gravity.CENTER;
windowManager.addView(fakeTextView, layoutParams);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
String orientationType = intent.getStringExtra("NEW_ORIENT_STRING_INTENT_EXTRA_KEY");
if (orientationType != null)
if (orientationType.equalsIgnoreCase("landscape")) {
mainLayoutParams.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
} else if (orientationType.equalsIgnoreCase("portrait")) {
mainLayoutParams.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
} else if (orientationType.equalsIgnoreCase("landscape_reverse")) {
mainLayoutParams.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
} else if (orientationType.equalsIgnoreCase("portrait_reverse")) {
mainLayoutParams.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
}
windowManager.updateViewLayout(fakeTextView, mainLayoutParams);
return START_STICKY;
}
Upvotes: 1
Views: 37