0

Just I want to know if there is a code that can detect if 'im calling someone with the default android phone app.. this is my code here and of course I need more hints

if(intent.getAction().equals("android.intent.action.PHONE_STATE")){
        String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
        if(intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
            call = true;
            Log.v("OUTGOING", String.valueOf(call));
            //Do-NOTHING
        } else {
            if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)){
                if (call == false) {
                    Log.v("OUTGOING", String.valueOf(call));
                    Log.v("CALL", "Call from " + numberPhone);
                    numberPhone = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
                }
            }
        }
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Mustapha
  • 13
  • 1
  • 4

1 Answers1

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

And set Receiver

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

Add Permission

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

you have to register the intent

IntentFilter intentFilter = new IntentFilter(Intent.ACTION_NEW_OUTGOING_CALL);
ctx.registerReceiver(outgoingReceiver, intentFilter);
Raut Darpan
  • 1,520
  • 9
  • 14
  • S.Raut could you explain the code? I just neeed to know the condition where the outgoing call is detected I already named my class as incomingCall so I focused from the first time in incoming calls so in the case of outgoing call the app will do nothing.. – Mustapha Oct 18 '16 at 18:27
  • **For outgoing calls, the system sends a broadcast action android.intent.action.NEW_OUTGOING_CALL.** we have create a Broadcast Receiver to detect it named **OutgoingReceiver** – Raut Darpan Oct 18 '16 at 18:37
  • So you mean that I need to create another class with another broadcastreceiver? – Mustapha Oct 18 '16 at 18:47
  • 1
    Please read carefully the new Google security regarding PROCESS_OUTGOUNG_CALLS permission(the app could be banned): https://support.google.com/googleplay/android-developer/answer/9047303 – Duna Oct 21 '19 at 07:27