[英]android Auto-Rotate configuration on change listener
I want to listen to 'Auto-Rotate' configuration change, not the device/system orientation, but to the toggle changes (on/off) 我想听“自动旋转”配置更改,而不是设备/系统方向,而是切换到切换更改(打开/关闭)
I believe i will have to sign up to configChange in the AndroidManifest and create a listener wherever i want but i'm not sure what is the correct config. 我相信我必须在AndroidManifest中注册configChange并在任何我想要的地方创建一个监听器,但我不确定什么是正确的配置。 IE
IE
android:configChanges='??'
But maybe another way exists and not through the android:configChanges
... 但也许存在另一种方式而不是通过
android:configChanges
......
you have to listen to Settings.System.ACCELEROMETER_ROTATION using a content observer. 你必须使用内容观察者收听Settings.System.ACCELEROMETER_ROTATION。
To register the content observer 注册内容观察者
getContentResolver().registerContentObserver(Settings.System.getUriFor
(Settings.System.ACCELEROMETER_ROTATION),
true,rotationObserver );
And declare it here. 并在此声明。 The onChange method will be called when the rotation is changed.
更改旋转时将调用onChange方法。
private ContentObserver rotationObserver = new ContentObserver(new Handler()) {
@Override
public void onChange(boolean selfChange) {
Do your task
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.