Sperren Sie die Ausrichtung des Android-Bildschirms auf Querformat

Ich entwickle eine Android-Anwendung, deren eine Funktion darin besteht, die Bildschirmausrichtung auf Querformat zu sperren. Ich möchte diese Ausrichtungsänderung auf alle Android-Anwendungen im Telefon anwenden. Ich benutze diesen Code

private void lockScreenOrientation() {
if (!mScreenOrientationLocked) {
    final int orientation = getResources().getConfiguration().orientation;
    final int rotation = getWindowManager().getDefaultDisplay().getOrientation();
    if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90) {
        if (orientation == Configuration.ORIENTATION_PORTRAIT) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
        else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        }
    }
    else if (rotation == Surface.ROTATION_180 || rotation == Surface.ROTATION_270) {
        if (orientation == Configuration.ORIENTATION_PORTRAIT) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
        }
        else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
        }
    }

    mScreenOrientationLocked = true;
}
}

private void unlockScreenOrientation() {
 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
 mScreenOrientationLocked = false;
}

Dies ist jedoch eine vorübergehende Änderung, die sich nicht auf alle Anwendungen auswirkt. Kennt jemand eine Möglichkeit, die Sperrenorientierung auf alle Anwendungen anzuwenden? Vielen Dank

Antworten auf die Frage(1)

Ihre Antwort auf die Frage