Question

I try to write a program for android. I want to make a call with my program and after that recognize the call status. With Flowing Function I can recognize the hang out status and for answering status it doesn’t work. I try this function but it doesn’t work either.

I want detect "call accepted" before "call died".

public class OutgoingCallReceiver extends BroadcastReceiver {
    protected static final String CLASS_TAG = "OutgoingCallReceiver : ";
    private static final String LOG_TAG = "MyActivity";
    private ConnectivityManager connectivityManager;
    private TelephonyManager telephonyManager;
    private NetworkInfo networkInfo;
    private String networkStauts = "Not connected !!";



    //************************************
    @Override
    public void onReceive(Context context, Intent intent) {


        //Toast.makeText(getApplicationContext(),String.valueOf(isPhoneCalling), Toast.LENGTH_SHORT).show();
        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);
        //Toast.makeText(getApplicationContext(),String.valueOf("phone number " + phonenumber), Toast.LENGTH_SHORT).show();
            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:
                        Context context = getApplicationContext();
                        Toast.makeText(getApplicationContext(), "RINGING", Toast.LENGTH_SHORT).show();
                        break;
                    case TelephonyManager.CALL_STATE_OFFHOOK:

                        Toast.makeText(getApplicationContext(), "OFFHOOK", Toast.LENGTH_SHORT).show();

                        isPhoneCalling = true;
                        break;
                    case TelephonyManager. CALL_STATE_IDLE:
                        if (isPhoneCalling) {
                            Toast.makeText(getApplicationContext(),
                                    "Your call is disconnected by receiver", 10000)
                                    .show();
                            Intent i = getBaseContext().getPackageManager()
                                    .getLaunchIntentForPackage(
                                             getBaseContext().getPackageName());
                             i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                             startActivity(i);

                             isPhoneCalling = false;
                             //duration=c.getLong(c.getColumnIndex(CallLog.Calls.DURATION));
                             Toast.makeText(getApplicationContext(), "IDLE", Toast.LENGTH_SHORT).show();
                            call();
                        }

                        break;
                    default:
                        Toast.makeText(getApplicationContext(), "1", Toast.LENGTH_SHORT).show();
                        //Log.d(LOG_TAG, CLASS_TAG + "Default: " + state);
                        break;
                    }
                }

            }, PhoneStateListener.LISTEN_CALL_STATE )
            //registerReceiver(phoneInfo, new IntentFilter(Intent.ACTION_NEW_OUTGOING_CALL));
        }

}

Was it helpful?

Solution

There is no solution to this problem. There is no API in Android which could detect a successfully placed outbound call.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top