7

アプリケーション内で回転を設定する例がたくさん見つかりましたが、問題が発生しているのは、[設定]、[表示]、[画面の自動回転](チェックボックス)にある電話の設定を切り替えることです。
電話の回転状態を確認し、反対(自動またはオフ)に設定してからアプリを閉じたいです。

これは私が持っているものです:

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();
        }
    }
}

さらに詳しい情報が必要な場合は、私に知らせてください:)
助けていただければ幸いです、それは私にストレスを与えています!!

4

1 に答える 1

5

正しい権限を設定しましたか?

私はしませんでした、そして例外詳細メッセージは言います、

"Permission Denial: writing com.android.providers.settings.SettingsProvider uri content://settings/system from pid=306, uid=10037 requires android.permission.WRITE_SETTINGS"

それはかなりそれを要約します。

于 2012-04-17T05:53:23.493 に答える