3

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.

arjun
  • 3,514
  • 4
  • 27
  • 48

4 Answers4

2

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);
Shayan Pourvatan
  • 11,898
  • 4
  • 42
  • 63
2

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.

  • `Believe me` hmm that's quite a scientific way to go! No joke, I'm not sure this answer is useful in any point – Ulysse BN Aug 23 '17 at 21:48
  • 1
    Well... According to the question (`Is there any way to detect outgoing calls?`) This is the better answer I can give. Since I already have searching enough about this topic. Not always a good investigation requiere an answer with many code lines. (Sorry for my english) – Adriana Hernández Aug 24 '17 at 14:40
  • I mean, If you've search a lot, either you didn't find anything which is realy sad. Either you found evidence to point out the fact there is **no way**. In this case, sharing these evidence to us would be a great way to improve your answer. – Ulysse BN Aug 24 '17 at 14:42
1

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

Community
  • 1
  • 1
Kirk
  • 4,957
  • 2
  • 32
  • 59
1

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();
        }

    }
Bala Vishnu
  • 2,588
  • 23
  • 20