gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:03:31 24 4
gpt4 key购买 nike

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

我本来打算再写一个 Profile 应用程序,但实际上内置的 Profiles 足以满足我的需求,我只需要自动切换它们即可。

最佳答案

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 .

关于android - 以编程方式切换 Android 配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7970990/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com