Tôi đã tìm thấy tải các ví dụ về cài đặt xoay trong phạm vi ứng dụng của bạn nhưng những gì tôi đang gặp phải là chuyển đổi cài đặt điện thoại tại: Cài đặt, Hiển thị, Tự động xoay màn hình (hộp kiểm).
Tôi muốn có thể kiểm tra trạng thái xoay của điện thoại, đặt nó ở trạng thái ngược lại (tự động hoặc tắt) và sau đó đóng ứng dụng.Android: Toggle Accelerometer Rotation State Setting
Đây là những gì tôi đã có:
import android.app.Activity;
import android.os.Bundle;
import android.provider.Settings;
import android.widget.Toast;
public class Rotation extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
try{
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();
finish();
}
else{
android.provider.Settings.System.putInt(getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 1);
Toast.makeText(Rotation.this, "Rotation ON", Toast.LENGTH_SHORT).show();
finish();
}
}
catch(Exception e){
e.printStackTrace();
Toast.makeText(Rotation.this, "Try failed!", Toast.LENGTH_SHORT).show();
finish();
}
}
}
nếu bạn cần biết thêm thông tin nào chỉ cho tôi biết :)
Any help is appreciated, nó nhấn mạnh tôi ra !!
Ứng dụng có hoạt động không? Điều gì sẽ xảy ra nếu không? – zapl
Không, không hoạt động. Nó chỉ cho thấy bắt và sau đó đóng lại. Tôi đã thử di chuyển các giá trị số xung quanh nhưng không thay đổi. Bất kỳ ý tưởng nào? –
+1 cho thủ thuật ... Tôi đã dành hàng giờ tìm kiếm điều này ... Cảm ơn –