Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switch Android profiles programmatically

Tags:

android

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.

like image 821
Laimoncijus Avatar asked Nov 01 '11 18:11

Laimoncijus


1 Answers

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.

like image 164
Arun Kumar Munusamy Avatar answered Oct 04 '22 22:10

Arun Kumar Munusamy