Android的切换配置文件编程 [英] Switch Android profiles programmatically

查看:125
本文介绍了Android的切换配置文件编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

时才有可能以某种方式编程开关内置的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?

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.

这篇关于Android的切换配置文件编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆