简体   繁体   English

应用程序启用方向更改按钮是状态栏

[英]Application enables orientation change button is status bar

I use nativescript in my project, also I always disable toggler on status bar menu on my Galaxy Alpha that allows orientation change. 我在我的项目中使用nativescript,我也总是在我的Galaxy Alpha上的状态栏菜单上禁用toggler,允许方向改变。 When I open my app the button status is set to enabled. 当我打开我的应用程序时,按钮状态设置为启用。 How to remove this behaviour? 如何删除此行为?

Here is an example of what button i mean, on this screen it called auto rotation. 这是我的意思是什么按钮的例子,在这个屏幕上它称为自动旋转。 https://lh4.ggpht.com/LuZ3y6wD4aUBdBvZ8Wxf73BpWdfbfNdxOVcHMuRVgRcyz-dl9rRNUwtpx-L9uPlgJdc=h900 https://lh4.ggpht.com/LuZ3y6wD4aUBdBvZ8Wxf73BpWdfbfNdxOVcHMuRVgRcyz-dl9rRNUwtpx-L9uPlgJdc=h900

Here is my manifest file: 这是我的清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="org.nativescript.AzoftDeviceTracking"
          android:versionCode="1"
          android:versionName="1.0">

    <supports-screens
            android:smallScreens="true"
            android:normalScreens="true"
            android:largeScreens="true"
            android:xlargeScreens="true"/>

    <uses-sdk
            android:minSdkVersion="17"
            android:targetSdkVersion="25"/>

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

    <application
            android:name="com.tns.NativeScriptApplication"
            android:allowBackup="true"
            android:icon="@drawable/icon"
            android:label="@string/app_name"
            android:theme="@style/AppTheme">

        <activity
                android:name="com.tns.NativeScriptActivity"
                android:label="@string/title_activity_kimera"
                android:configChanges="keyboardHidden|screenSize"
                android:theme="@style/LaunchScreenTheme"
                android:screenOrientation="portrait">

            <meta-data android:name="SET_THEME_ON_LAUNCH" android:resource="@style/AppTheme"/>

            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity android:name="com.tns.ErrorReportActivity"/>
    </application>
</manifest>

UPDATE Ok, I found possible reason but can't find it in nativescript code. 更新好的,我发现可能的原因但无法在nativescript代码中找到它。

Have you tried this out, I used it in my project and it works fine 你试过这个,我在我的项目中使用它,它工作正常

npm nativescript-screen-orientation npm nativescript-screen-orientation

This should do the trick for you: 这应该是你的诀窍:

import android.provider.Settings;
public static void setAutoOrientationEnabled(Context context, boolean enabled)
{
      Settings.System.putInt( context.getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, enabled ? 1 : 0);
}

Add permission to the AndroidManifest.xml 添加AndroidManifest.xml的权限

I had the excact same problem. 我有同样的问题。 What I ended up with was using an OrientationListener to detect when the user had actually tilted the phone to landscape and then setting the orientation to SCREEN_ORIENTATION_SENSOR. 我最终得到的是使用OrientationListener来检测用户何时实际将手机倾斜为横向,然后将方向设置为SCREEN_ORIENTATION_SENSOR。

OrientationEventListener orientationEventListener = new OrientationEventListener(getActivity()) {
@Override
public void onOrientationChanged(int orientation) {
    int epsilon = 10;
    int leftLandscape = 90;
    int rightLandscape = 270;
    if(epsilonCheck(orientation, leftLandscape, epsilon) ||
       epsilonCheck(orientation, rightLandscape, epsilon)){
            getMainActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
        }
    }

    private boolean epsilonCheck(int a, int b, int epsilon) {
        return a > b - epsilon && a < b + epsilon;
    }
};
orientationEventListener.enable();

You would also need to add checks for portrait , because you described needing that in your original post. 您还需要添加纵向检查,因为您在原始帖子中描述了需要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM