Thursday, June 21, 2012

Change Loud & Silent Mode Programmatically In Android


Here i have explained about changing Loud mode to Silent mode and Silent mode to Loud mode programmatically in android.ProfileChanger
Code

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

}

}
});
}
}


Here is your output.



You can download the source here
Arun Kumar Munusamy Web Developer

Morbi aliquam fringilla nisl. Pellentesque eleifend condimentum tellus, vel vulputate tortor malesuada sit amet. Aliquam vel vestibulum metus. Aenean ut mi aucto.

4 comments:

  1. Is is possible to switch to outdoor and other customized user profiles?

    ReplyDelete
  2. I was creating an app that would toggle the phones silent mode depending on the time at which the phone would be in. For example, if the phone's time service shows that it is in the time which will set by the user then it would automatically go silent. My question is how to get the phone to go to silent and then turn on to the original volume automatically

    ReplyDelete