I think each android device has an abitily to on/off auto-rotating function. Usually you can find it in settings->display->auto-rotate on/off
. How can I read this setting state from my application? How can I access to this setting value? If you can share a code snipped i'd be very appreciate it.
Hope this code snippet helps you out:-
@Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);
if (android.provider.Settings.System.getInt(getContentResolver(),
Settings.System.ACCELEROMETER_ROTATION, 0) == 1){
Toast.makeText(getApplicationContext(), "Rotation ON", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(getApplicationContext(), "Rotation OFF", Toast.LENGTH_SHORT).show();
}
super.onCreate(savedInstanceState);
}
Use the following code:
if (android.provider.Settings.System.getInt(getContentResolver(), android.provider.Settings.System.ACCELEROMETER_ROTATION, 0) == 1) {
Toast.makeText(Rotation.this, "Rotation ON", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(Rotation.this, "Rotation OFF", Toast.LENGTH_SHORT).show();
}
Try this:
public static void setAutoOrientationEnabled(ContentResolver resolver, boolean enabled)
{
Settings.System.putInt( context.getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, enabled ? 1 : 0);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.