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
Thanks :)
ReplyDeletethankiiiiii
ReplyDeleteIs is possible to switch to outdoor and other customized user profiles?
ReplyDeleteI 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