I used the same code that it works when we are given a dial number, this is a number that cannot be included *, #. and in the manifest file we have to declare the receiver this way
<receiver android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
and recording permission <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
Just check out the edited code below:
Use BroadcastReceiver as follows:
public class MyOutgoingCallHandler extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String phoneNumber = getResultData();
if (phoneNumber == null) {
phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
}
if(phoneNumber.equals("1234")){
setResultData(null);
Intent i=new Intent(context,MainActivity.class);
i.putExtra("extra_phone", phoneNumber);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
}
<receiver android:name="MyOutgoingCallHandler">
<intent-filter >
<action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
</intent-filter>
</receiver>
:
, , ,
String phone=getIntent().getStringExtra("extra_phone");
if(!phone.equals(null)){
Toast.makeText(getBaseContext(), phone, Toast.LENGTH_LONG).show();
}
, BroadcastReceivers , Right Number