How to find outgoing number in telephony manager

I use this:

public void onCallStateChanged(int state, String incomingNumber)

which listens:

telephonyManager.listen(listener,PhoneStateListener.LISTEN_CALL_STATE);

I want to know both outgoing and incoming calls, but at the moment I only receive incoming calls (when state changes occur). Can someone tell me when I can determine the outgoing call and its end.

There is also a way to simulate outgoing calls in an Eclipse emulator. was able to do this for incoming calls through the control emulator in eclipse.

+5
source share
2 answers

string android.intent.action.NEW_OUTGOING_CALL string android.intent.action.NEW_OUTGOING_CALL IntentFilter AndroidMenifest PROCESS_OUTGOING_CALLS. . , , -. .

public static final String outgoing = "android.intent.action.NEW_OUTGOING_CALL" ;
IntentFilter intentFilter = new IntentFilter(outgoing);
BroadcastReceiver OutGoingCallReceiver = new BroadcastReceiver()
{
    @Override
    public void onReceive(Context context, Intent intent) 
    {
        // TODO Auto-generated method stub
        String outgoingno = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
        Toast.makeText(context, "outgoingnum =" + outgoingno,Toast.LENGTH_LONG).show();
    }
};
registerReceiver(brForOutgoingCall, intentFilter);
+13

, MyPhoneReceiver, BroadcastReceiver onReceive.

public class MyPhoneReceiver extends BroadcastReceiver{
    @Override
    public void onReceive(Context context, Intent intent){

        String phoneNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);

    }
}

, , MainActivity.class onCreate. .

    IntentFilter filter = new IntentFilter("android.intent.action.NEW_OUTGOING_CALL");
    MyPhoneReceiver myPhoneReceiver = new MyPhoneReceiver();
    registerReceiver(myPhoneReceiver,filter);

AndroidManifest.xml

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

AndroidManifest.xml, :

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

All Articles