アプリケーション内で回転を設定する例がたくさん見つかりましたが、問題が発生しているのは、[設定]、[表示]、[画面の自動回転](チェックボックス)にある電話の設定を切り替えることです。
電話の回転状態を確認し、反対(自動またはオフ)に設定してからアプリを閉じたいです。
これは私が持っているものです:
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();
}
}
}
さらに詳しい情報が必要な場合は、私に知らせてください:)
助けていただければ幸いです、それは私にストレスを与えています!!