Reputation: 77
I start 'Activity' using 'startActivity(callintent)' and wait for some time. Then I need to stop the call with 'onReceive()'. In this 'onReceive()' method how can I get the existing ongoing call phone number?
@Override
public void onReceive(Context context, Intent intent) {
String oldnumber = intent.getStringExtra(intent.ACTION_NEW_OUTGOING_CALL);
String newphnumber="9999999999";
if ((newphnumber1=null) &&(newphnumber!=oldnumber)) {
String msg = "Intercepted outgoing call. Old :" + oldnumber +
", new :" + newPhNnumber;
Toast.makeText(getApplicationContext(), "end call", Toast.LENGTH_SHORT).
show();
setResultData(newphnumber);
}
}
Here oldnumber
means already activated outgoing number (single call is going). How can I get it?
Upvotes: 2
Views: 5530
Reputation: 452
We can get the ongoing call number easily using BroadcastReceiver. In your BroadcastReceiver class onReceive function you have to code like following,
if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER).toString();
Log.w("", "Number---->"+number);
Toast.makeText(context, "Intent Received", Toast.LENGTH_LONG).show();
}
and in your Activity class
MReciever mReceiver;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mReceiver = new MReciever();
IntentFilter filter = new IntentFilter(Intent.ACTION_NEW_OUTGOING_CALL);
registerReceiver(mReceiver, filter);
}
protected void onDestroy() {
unregisterReceiver(mReceiver);
};
And in your Android manifest file you have to declare your receiver as
<receiver android:name=".YourReceiverClass" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
I think this will help you.
Upvotes: 3