I've an issue setting the ringing volume in Android.
I'm working in a videocall app, so I need to make the phone sound when receive a call. The problem is, with the same code, if I make the phone sound in a outgoing call (for testing purposes) I'm able to manage the ringtone nice. Otherwise, in an incoming call, when I try to modify the volume, the audio sounds really weird.
I mean, there is an incoming call, the phone start the ringtone nice, but if I press on the key up volume, the ringing volume change first with a really low sound, and then changes again raising the volume up, and finally the ringtone keeps in the same volume than before (this change, from low to loud, happens in 1 second approx.).
I think the only difference between the outgoing call activity and the incoming call activity is that the first one is created tapping in a button, and the second one is created through a service which manages the incoming calls.
Here is my code to manage the ringing tone:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//.....more code.....
BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
switch (am.getRingerMode()) {
case AudioManager.RINGER_MODE_SILENT:
log.debug("Ringing: Silent");
break;
case AudioManager.RINGER_MODE_VIBRATE:
log.debug("Ringing: Vibrate");
break;
case AudioManager.RINGER_MODE_NORMAL:
log.debug("Ringing: Normal");
break;
}
}
};
IntentFilter filter = new IntentFilter(
AudioManager.RINGER_MODE_CHANGED_ACTION);
registerReceiver(receiver, filter);
setVolumeControlStream(AudioManager.STREAM_RING);
startRinging();
}
private Ringtone r;
private void startRinging() {
if ((r != null) && (r.isPlaying())) {
return;
}
Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
r = RingtoneManager.getRingtone(getApplicationContext(), ringtone);
r.play();
}
Well...repeat, the same code works if I start the activity "by myself" (tested in an outgoing call activity), but if the activity is created through the service I cannot manage the ring stream properly. I don't know if that difference when create an activity is making the issue...
Here is the code from where I create the incoming call activity:
private final IncomingCallHandler incomingCallHandler = new IncomingCallHandler() {
@Override
public void onIncomingCall(IncomingCall call) {
Class<?> activityClass = AppUtils
.getClassByName(getString(R.string.incoming_call_package));
if (activityClass == null)
return;
Intent i = new Intent(ctx, activityClass);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra(PARAM_INCOMING_CALL, call);
startActivity(i);
}
};
I need to get the activity using a string because is a configurable parameter, I cannot change that (and I don't think that is the problem).
Thanks a lot!! If someone need more information let me know!
Jorge.
Aucun commentaire:
Enregistrer un commentaire