How To Detect The End Of Outgoing Ringtone?
I want to make a call with my program and after that recognize the call status . I want to detect the end of outgoing ringtone. How to detect the end of outgoing ringtone ? I use
Solution 1:
Following code snippet can help you in finding the phone call current statue whether its picked, ringing or idle. You can easily use these states and implement your functionality accordingly.
privateclassCustomPhoneStateListenerextendsPhoneStateListener
{
@OverridepublicvoidonCallStateChanged(int state, String incomingNumber)
{
super.onCallStateChanged(state, incomingNumber);
//TelephonyManager.CALL_STATE_IDLE//TelephonyManager.CALL_STATE_OFFHOOK//TelephonyManager.CALL_STATE_RINGING
}
}
Solution 2:
Check by This:- you will be able to call user
IntentcallIntent=newIntent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:+9189745847"));
startActivity(callIntent);
and also use in androidmanifest.xml file:
<uses-permissionandroid:name="android.permission.CALL_PHONE" />
Solution 3:
Have a look at intent NEW_OUTGOING_CALL
<receiverandroid:name=".receiver.OutgoingCallReceiver" ><intent-filter><actionandroid:name="android.intent.action.NEW_OUTGOING_CALL" /></intent-filter></receiver>
Then you can check the state of call with a PhoneStateListener :
publicclassOutgoingCallReceiverextendsBroadcastReceiver {
protectedstaticfinalStringCLASS_TAG="OutgoingCallReceiver : ";
@OverridepublicvoidonReceive(Context context, Intent intent) {
Bundlebundle= intent.getExtras();
if(null == bundle) return;
Stringphonenumber= intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
Log.i(LOG_TAG, CLASS_TAG + "phone number " + phonenumber);
finalTelephonyManagertm= (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
tm.listen(newPhoneStateListener() {
@OverridepublicvoidonCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
Log.d(LOG_TAG, CLASS_TAG + "RINGING");
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Log.d(LOG_TAG, CLASS_TAG + "OFFHOOK");
Process.onCallStateIsOFFHOOK();
break;
case TelephonyManager.CALL_STATE_IDLE:
Process.onCallStateIsIDLE();
Log.d(LOG_TAG, CLASS_TAG + "IDLE");
break;
default:
Log.d(LOG_TAG, CLASS_TAG + "Default: " + state);
break;
}
}
}, PhoneStateListener.LISTEN_CALL_STATE);
}
}
In the Process class you can detect the ringtone and create more state like CALLBEGINS, CALLANSWERED by recording the VOICE_CALL. Example of onCallStateIsIDLE() :
publicvoidonCallStateIsIDLE() {
setSpeakingOn(false);
if (stateCall == STATE_CALLANSWERED ||
stateCall == STATE_CALLBEGINS ||
stateCall == STATE_DIALISOFFHOOK ||
stateCall == STATE_DIALENDREQUESTED) {
Log.i(LOG_TAG, CLASS_TAG + " - forcing state : STATE_DIALREADY : old state = " + stateCall);
stateCall = STATE_DIALREADY;
}
}
Post a Comment for "How To Detect The End Of Outgoing Ringtone?"