I am using the twilio for making the call and receiving the call. I am receiving the incoming call by using intent in onResum() method.How to get incoming number by using intent on connection.Also I want display customise popup when mobile screen will be lock.
This is my code for receiving call.
@Override
public void onResume() {
super.onResume();
Intent intent = getIntent();
if (intent != null) {
/*
* Determine if the receiving Intent has an extra for the incoming connection. If so,
* remove it from the Intent to prevent handling it again next time the Activity is resumed
*/
Device device = intent.getParcelableExtra(Device.EXTRA_DEVICE);
Connection incomingConnection = intent.getParcelableExtra(Device.EXTRA_CONNECTION);
// Intent broadcast = new Intent(this, PhoneStateReceiver.class);
// NewVoiceCallFragment client = new NewVoiceCallFragment(incomingConnection);
// Intent intent1 = new Intent(this, CallDetectService.class);
String incoming_number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
if (incomingConnection == null && device == null) {
return;
}
intent.removeExtra(Device.EXTRA_DEVICE);
intent.removeExtra(Device.EXTRA_CONNECTION);
pendingConnection = incomingConnection;
pendingConnection.setConnectionListener(this);
mobjSessionManager.setKeyIncomingCollsid(pendingConnection.getParameters().get(incomingConnection.IncomingParameterCallSIDKey));
String incomingRecipientCallSid = pendingConnection.getParameters().get(incomingConnection.IncomingParameterCallSIDKey);
String incomingRecipientCallNumber = pendingConnection.getParameters().get(incomingConnection.IncomingParameterFromKey);
if (incomingRecipientCallNumber.equals(mobjSessionManager.getKeyCallerid())) {
tManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
if (isDisplayDilog) {
switch (getRingingMode())
{
case 1:
audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
break;
case 2:
audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
break;
case 3:
audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
break;
}
// audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
// AsyninvokeIncomingNumber ser=new AsyninvokeIncomingNumber();
// ser.execute();
// Device.State str=device.getState();
unlockScreen();
showIncomingDialog();
}
}
}
}
//for ring :
private int getRingingMode()
{
AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
switch (am.getRingerMode()) {
case AudioManager.RINGER_MODE_SILENT:
return 1;
// break;
case AudioManager.RINGER_MODE_VIBRATE:
return 2;
// break;
case AudioManager.RINGER_MODE_NORMAL:
return 3;
// break;
}
return 0;
}
// for unlock screen
private void unlockScreen() {
Window window = this.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
}