设置自动旋转启用/禁用的Andr​​oid [英] Set Auto-Rotate Enabled/Disabled Android

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

问题描述

我工作的一个Android应用程序,为此,我希望用户能够以preSS一个按钮,或者启用或禁用自动旋转。我怎样才能做到这一点,意图?我想像我会以某种方式需要改变ACCELEROMETER_ROTATION为0或1,但我不知道如何做到这一点precisely。我希望也许你们的人能帮助我!

I am working on an Android app, for which I would like the user to be able to press a button which either enables or disables auto-rotate. How can I do this with an Intent? I'd imagine I would somehow need to change ACCELEROMETER_ROTATION to 0 or 1, but I don't know how to do this precisely. I hope maybe one of you guys can help me out!

推荐答案

您可以切换旋转ON / OFF使用ACCELEROMETER_ROTATION为:

You can toggle Rotation ON/OFF using ACCELEROMETER_ROTATION as :

if  (android.provider.Settings.System.getInt(getContentResolver(),Settings.System.ACCELEROMETER_ROTATION, 0) == 1){
    android.provider.Settings.System.putInt(getContentResolver(),Settings.System.ACCELEROMETER_ROTATION, 0);
    Toast.makeText(Rotation.this, "Rotation OFF", Toast.LENGTH_SHORT).show();
    }
else{
    android.provider.Settings.System.putInt(getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 1);
    Toast.makeText(Rotation.this, "Rotation ON", Toast.LENGTH_SHORT).show();
    }

终于在Manifast添加 android.permission.WRITE_SETTINGS 许可

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

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