启用和禁用自动旋转编程? [英] Enable and disable auto rotate programatically?

查看:298
本文介绍了启用和禁用自动旋转编程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有很多很酷的小工具在那里,将启用和禁用自动旋转您的手机上。在所有的应用程序禁用它把它关了手机上。

There are a lot of cool widgets out there that will enable and disable auto rotate on your phone. Disabling it turns it off across all apps on the phone.

任何想法如何,他们都完成了吗?

Any ideas how they are accomplishing it?

推荐答案

这应该做的伎俩为您提供:

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);
    }

添加权限,AndroidManifest.xml中

Add permission to the AndroidManifest.xml

<uses-permission android:name="android.permission.WRITE_SETTINGS" />

您可以找到文件<一个href="http://developer.android.com/reference/android/provider/Settings.System.html#ACCELEROMETER_ROTATION">here

这篇关于启用和禁用自动旋转编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆