Reputation: 3137
I have to post the code to understand what i want to say:
public void répondre()
{
mt = MediaPlayer.create(context,R.raw.ringtone);
mt.setVolume(5,5);
mt.start();
mt.setLooping(true);
//startActivity((new Intent(Intent.ACTION_ANSWER)));
AlertDialog.Builder ad = new AlertDialog.Builder(context);
ad.setTitle("Appel en cours...");
ad.setMessage("Voulez vous répondre à cet appel?");
ad.setPositiveButton("Oui",
new OnClickListener() {
public void onClick(DialogInterface dialog,
int arg1) {
mt.stop();
SipAudioCall incomingCall = null;
try {
SipAudioCall.Listener listener = new SipAudioCall.Listener() {
@Override
public void onRinging(SipAudioCall call, SipProfile caller) {
try {
call.answerCall(30);
} catch (Exception e) {
Log.d("Call not answered","Call not answered",e);
}
}
};
SIPCommunicator wtActivity = (SIPCommunicator) context;
incomingCall = wtActivity.manager.takeAudioCall(intent, listener);
incomingCall.answerCall(30);
incomingCall.startAudio();
incomingCall.setSpeakerMode(true);
if(incomingCall.isMuted()) {
incomingCall.toggleMute();
}
wtActivity.call = incomingCall;
String useName = wtActivity.call.getPeerProfile().getDisplayName();
wtActivity.updateStatus("Vous êtes en communication avec " + useName);
} catch (Exception e) {
if (incomingCall != null) {
incomingCall.close();
}
}
}
});
I want to show the caller's name(useName
variable) in the AlertDialog. If i put this line(String useName = wtActivity.call.getPeerProfile().getDisplayName();
) before MediaPlayer
and make ad.setTitle("Appel en cours"+useName);
the variable useName
is null
! So how doing this ?
Thank you very much.
Upvotes: 0
Views: 143
Reputation: 11028
Fortunatelly, we do not need to break causality as indicated in the question title. Thing is (and that is not something so uncommon with phone applications handling) that in the moment when you get indication about incoming call, caller name is not ready. It is because it takes some time until callers number/uri has to be searched for in the contacts.
So, in order to handle this issue I would suggest that you do one of the following:
So, in any case you need to update your AlertDialog some safe time after incoming call is indicated.
Upvotes: 2