I am using the Broadcast receiver to detect the outgoing calls and the following code is working fine in an independent code.
My question is, how can i call this method in my main activity, since i want to compare the string number and do an action then. Please help me! Thanks.
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
public class OutgoingCallReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
Log.d("DEBUG", "RINGING (outgoing call) with number: " + number);
Toast.makeText(context, "Outgoing call number: " + number, Toast.LENGTH_LONG).show();
}
}