以编程方式启用和禁用自动旋转? [英] Enable and disable auto rotate programmatically?

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

问题描述

有很多很酷的小部件,它们可以在您的手机上启用和禁用自动旋转.禁用它会在手机上的所有应用程序中将其关闭.

有什么想法可以实现吗?

解决方案

这应该为您解决问题:

    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添加权限

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

您可以在此处找到文档

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

Add permission to the AndroidManifest.xml

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

You can find the documentation here

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

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