How to Change phone Profile

//Construct object of Audio Manager
AudioManager audMangr;
audMangr= (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);

//For Normal mode
audMangr.setRingerMode(AudioManager.RINGER_MODE_NORMAL);

//For Silent mode
audMangr.setRingerMode(AudioManager.RINGER_MODE_SILENT);

//For Vibrate mode
audMangr.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);

source code
Java class

package com.silent;

import android.app.Activity;
import android.content.Context;
import android.media.AudioManager;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class silentView extends Activity implements OnClickListener {
/** Called when the activity is first created. */

Button btns;
Button btng;

AudioManager audMangr;
TextView tv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btns=(Button)findViewById(R.id.button1);
btng=(Button)findViewById(R.id.button2);

btns.setOnClickListener(this);
btng.setOnClickListener(this);

audMangr= (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);


}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
tv=(TextView)findViewById(R.id.textView1);
if(arg0==btns)
{
tv.setText("Silent Profile Activated");
//For Silent mode
audMangr.setRingerMode(AudioManager.RINGER_MODE_SILENT);
}
if(arg0==btng)
{
tv.setText("General Profile Activated");
//For Normal mode
audMangr.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
}

}

}


main.xml









Output Application
Press on Silent Button to change Android phone mode Silent
and for General Press General Button




Post a Comment

1 Comments

  1. really helpful post, I like your blog. your earning ideas are so simple and really work from . Now I am earning from Linkedin , sproutgigs and OTP services. thanks for your helpful blog.

    ReplyDelete