以编程方式切换Android配置文件

时间:2011-11-01 18:22:39

标签: android

是否有可能以某种方式以编程方式切换内置的Android配置文件?

我打算编写另一个Profile应用程序,但实际内置的Profiles已经足够满足我的需求,我只需要自动切换它们。

1 个答案:

答案 0 :(得分:4)

public class ProfileChangerActivity extends Activity {

    /** Called when the activity is first created. */

    ToggleButton tbt;
    TextView txtview;

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    tbt = (ToggleButton) findViewById(R.id.togglebutton);
    txtview = (TextView) findViewById(R.id.textview);
    txtview.setText("Welcome to Profile Changer Application");
    final AudioManager mobilemode = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);

    tbt.setOnClickListener(new OnClickListener() {

    public void onClick(View v) {
    // TODO Auto-generated method stub

    if(tbt.getText().toString().equals("Switch to LOUD"))
    {
    mobilemode.setRingerMode(AudioManager.RINGER_MODE_SILENT);
    txtview.setText("SILENT profile activated !");
    Toast.makeText(getBaseContext(),"SILENT profile activated ",Toast.LENGTH_LONG).show();
    }
    else if(tbt.getText().toString().equals("Switch to SILENT"))
    {
    mobilemode.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
    txtview.setText("LOUD profile activated !");
    Toast.makeText(getBaseContext(),"LOUD profile activated !",Toast.LENGTH_LONG).show();

    }

    }
    });
    }
    }

来源link