arjun
arjun

Reputation: 3574

Detecting outgoing calls in android

I need detect the outgoing calls and send the number as text message to another number. Is there any way to detect outgoing calls. I have tried phonestatelistener but it doesn't work.

Upvotes: 3

Views: 3869

Answers (4)

Adriana Hernández
Adriana Hernández

Reputation: 1055

If you mean detect the time of an outgoing call starts ringing on the other phone, then I can tell that there is NO way (sadly) to do that.

It's impossible to detect by regular non-system application - no Android API. I could not find a way, I was googling the solution within very long time.

Upvotes: 2

Shayan Pourvatan
Shayan Pourvatan

Reputation: 11948

please see following link to Detect Outgoing call:

Detecting incoming and outgoing phone calls on Android

ACTION_NEW_OUTGOING_CALL

public class OutgoingReceiver extends BroadcastReceiver {
     public OutgoingReceiver() {
     }

     @Override
     public void onReceive(Context context, Intent intent) {
         String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);

         Toast.makeText(ctx, 
           "Outgoing: "+number, 
           Toast.LENGTH_LONG).show();
     }
}

Register the broadcast receiver:

IntentFilter intentFilter = new IntentFilter(Intent.ACTION_NEW_OUTGOING_CALL);
ctx.registerReceiver(outgoingReceiver, intentFilter);

Upvotes: 2

Bala Vishnu
Bala Vishnu

Reputation: 2628

Try this code

private class CallStateListener extends PhoneStateListener {
        @Override
        public void onCallStateChanged(int state, String incomingNumber) {
            switch (state) {
            case TelephonyManager.CALL_STATE_RINGING:
                number = incomingNumber;
                Thread_calls.run();
                //Toast.makeText(ctx, "Incoming: " + incomingNumber,Toast.LENGTH_LONG).show();
                break;
            }
        }
    }

    public class OutgoingReceiver extends BroadcastReceiver {
        public OutgoingReceiver() {
        }

        @Override
        public void onReceive(Context context, Intent intent) {
            number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
            Thread_calls.run();
            //Toast.makeText(ctx, "Outgoing: " + number, Toast.LENGTH_LONG).show();
        }

    }

Upvotes: 1

Kirk
Kirk

Reputation: 5077

I hope this will help you

Uri allCalls = Uri.parse("content://call_log/calls");
Cursor c = managedQuery(allCalls, null, null, null, null);

String num= c.getString(c.getColumnIndex(CallLog.Calls.NUMBER));// for  number
String name= c.getString(c.getColumnIndex(CallLog.Calls.CACHED_NAME));// for name
String duration = c.getString(c.getColumnIndex(CallLog.Calls.DURATION));// for duration
int type = Integer.parseInt(c.getString(c.getColumnIndex(CallLog.Calls.TYPE)));// for call     type, Incoming or out going

and a tutorial for more information Link

source

Upvotes: 1

Related Questions