Android的切换配置文件编程配置文件、Android

2023-09-06 02:47:36 作者:注定孤独终老

时才有可能以某种方式编程开关内置的Andr​​oid档案?

我正打算写另一个档案的应用程序,但实际上建在配置文件是绰绰有余了我的需求,我只需要切换到自动化的方式。

解决方案

 公共类ProfileChangerActivity延伸活动{

    / **第一次创建活动时调用。 * /

    切换按钮技术性贸易壁垒;
    TextView的txtview;

    @覆盖
    公共无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.main);

    TBT =(切换按钮)findViewById(R.id.togglebutton);
    txtview =(TextView中)findViewById(R.id.textview);
    txtview.setText(欢迎来到简介换应用程序);
    最后AudioManager mobilemode =(AudioManager)this.getSystemService(Context.AUDIO_SERVICE);

    tbt.setOnClickListener(新OnClickListener(){

    公共无效的onClick(视图v){
    // TODO自动生成方法存根

    如果(tbt.getText()的toString()。等于(切换到LOUD))
    {
    mobilemode.setRingerMode(AudioManager.RINGER_MODE_SILENT);
    txtview.setText(无声情景模式激活!);
    Toast.makeText(getBaseContext(),无声情景模式激活,Toast.LENGTH_LONG).show();
    }
    否则,如果(tbt.getText()的toString()。等于(切换到静音))
    {
    mobilemode.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
    txtview.setText(LOUD配置文件激活!);
    Toast.makeText(getBaseContext(),LOUD个人资料被激活!,Toast.LENGTH_LONG).show();

    }

    }
    });
    }
    }
 

来源链接。

Is is possible somehow programmatically switch built in Android Profiles?

Android Studio文件编码的设置

I was planning to write yet another Profile app, but actually built in Profiles are more than enough for my needs, I just would need to switch them automated way.

解决方案

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

    }

    }
    });
    }
    }

Source link.