启用和禁用自动旋转编程?

由网友(太冷的回忆)分享简介:有很多很酷的小工具在那里,将启用和禁用自动旋转您的手机上。在所有的应用程序禁用它把它关了手机上。There are a lot of cool widgets out there that will enable and disable auto rotate on your phone. Disabling it...

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

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" />

您可以找到文件here

阅读全文

相关推荐

最新文章