how to detect the end of outgoing ringtone?

一个人想着一个人 提交于 2019-12-24 16:01:12

问题


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 of Flowing code for make call .

EditText ed = (EditText) findViewById(R.id.txtcall);        
Uri uri = Uri.fromParts("tel", ed.getText().toString(), null);
callIntent = new Intent(Intent.ACTION_CALL,uri);
startActivity(callIntent);

回答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.

 private class CustomPhoneStateListener extends PhoneStateListener
 {        
            @Override
            public void onCallStateChanged(int state, String incomingNumber) 
            {
                super.onCallStateChanged(state, incomingNumber);

                //TelephonyManager.CALL_STATE_IDLE
                //TelephonyManager.CALL_STATE_OFFHOOK
                //TelephonyManager.CALL_STATE_RINGING
            }
 }



回答2:


Check by This:- you will be able to call user

Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:+9189745847"));
startActivity(callIntent);

and also use in androidmanifest.xml file:

 <uses-permission android:name="android.permission.CALL_PHONE" />



回答3:


Have a look at intent NEW_OUTGOING_CALL

 <receiver android:name=".receiver.OutgoingCallReceiver" >
        <intent-filter>
            <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
        </intent-filter>
    </receiver>

Then you can check the state of call with a PhoneStateListener :

public class OutgoingCallReceiver extends BroadcastReceiver {

protected static final String CLASS_TAG = "OutgoingCallReceiver : ";

@Override
public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getExtras();
    if(null == bundle) return;

    String phonenumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
    Log.i(LOG_TAG, CLASS_TAG + "phone number " + phonenumber);

        final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        tm.listen(new PhoneStateListener() {
            @Override
            public void onCallStateChanged(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() :

public void onCallStateIsIDLE() {
    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;
    }
}


来源:https://stackoverflow.com/questions/14889863/how-to-detect-the-end-of-outgoing-ringtone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!