I have made the custom dialer and in that i have set the tone in button's press event.Now the problem is that i have set the volume is fixed at this time so when the phone is in silence mode then from application tone is also played.So i want to customize based on phone's dialer key volume.The code for custome dialer is below:
public void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.keypad1);
ctx = this;
b1 = (ImageButton) findViewById(R.id.imageButton1);
b2 = (ImageButton) findViewById(R.id.imageButton2);
b3 = (ImageButton) findViewById(R.id.imageButton3);
b4 = (ImageButton) findViewById(R.id.imageButton4);
b5 = (ImageButton) findViewById(R.id.imageButton5);
b6 = (ImageButton) findViewById(R.id.imageButton6);
b7 = (ImageButton) findViewById(R.id.imageButton7);
b8 = (ImageButton) findViewById(R.id.imageButton8);
b9 = (ImageButton) findViewById(R.id.imageButton9);
b10 = (ImageButton) findViewById(R.id.imageButtonstar);
b11 = (ImageButton) findViewById(R.id.imageButton0);
b12 = (ImageButton) findViewById(R.id.imageButtonhash);
call = (ImageButton) findViewById(R.id.imageButtoncall);
back = (ImageButton) findViewById(R.id.back);
logout = (ImageButton) findViewById(R.id.imageButtonlogout);
keypad = (ImageButton) findViewById(R.id.imageButtondialpad);
txt = (EditText) findViewById(R.id.txtnum);
/*AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
int streamMaxVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
Log.i("volume",""+streamMaxVolume);*/
mp1 = new ToneGenerator(AudioManager.STREAM_DTMF,70);
txt.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
txt.setSelection(txt.getText().length());
}
});
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
s = txt.getText().toString();
txt.setText(s + "1");
mp1.stopTone();
mp1.startTone(ToneGenerator.TONE_DTMF_1, 120);
}
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
s = txt.getText().toString();
txt.setText(s + "2");
mp1.stopTone();
mp1.startTone(ToneGenerator.TONE_DTMF_2, 120);
}
});
b3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
s = txt.getText().toString();
txt.setText(s + "3");
mp1.stopTone();
mp1.startTone(ToneGenerator.TONE_DTMF_3, 120);
}
});
b4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
s = txt.getText().toString();
txt.setText(s + "4");
mp1.stopTone();
mp1.startTone(ToneGenerator.TONE_DTMF_4, 120);
}
});
b5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
s = txt.getText().toString();
txt.setText(s + "5");
mp1.stopTone();
mp1.startTone(ToneGenerator.TONE_DTMF_5, 120);
}
});
One suggested solution could be, if you don't want to play the key tone in silent mode then you have to detect the phone ringer mode weather is it silent or not