English 中文(简体)
机器人设置 - 设置. system.
原标题:Android setting - Settings.system.ACCELOROMETER_ROTATION is not working

我这里似乎有一个错误。 我正在尝试改变设置中的加速计自动旋转值 。

现在,我设法锁定和解锁旋转设备。 但是,每当我锁定设备时,它就会进入肖像模式, 无论我锁定它时方向如何。

这是我的代码:

    public void setAutoOrientationEnabled(boolean enabled)
{
  Settings.System.putInt(content, Settings.System.ACCELEROMETER_ROTATION, enabled ? 1 : 0);
}

谢谢你的帮助!

问题回答

此代码样本锁定/ 解锁屏幕旋转, 锁定时保留当前方向 :

if (Settings.System.getInt(context.getContentResolver(), Settings.System.ACCELEROMETER_ROTATION) == 1) {
            Display defaultDisplay = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
            Settings.System.putInt( context.getContentResolver(), Settings.System.USER_ROTATION, defaultDisplay.getRotation());
            Settings.System.putInt( context.getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0);       
} else {
            Settings.System.putInt( context.getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 1);                
}
   int orientation = this.getRequestedOrientation();
        int rotation = ((WindowManager) this.getSystemService(
                Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation();
        switch (rotation) {
            case Surface.ROTATION_0:
                Settings.System.putInt(getContentResolver(), Settings.System.USER_ROTATION, 1);
                orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
                break;
            case Surface.R`enter code here`OTATION_90:
                Settings.System.putInt(getContentResolver(), Settings.System.USER_ROTATION, 0);
                orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
                break;
        }

        this.setRequestedOrientation(orientation);




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签