Possible Duplicate:
launching my app when dialing a number
I would like to get the mobile number from dialer which has dialed by user in my android application.I have implemented an application as follows:
((Button)findViewById(R.id.button1)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse("tel:")));
}
});
from the above code i can open dialer app.If user enter a mobile number and click for call then i would like to get which number he has typed. please any body help on it...
You can use BroadcastReceiverto do that :
Register a BroadcastReceiver like this in Manifest file:
<!-- DIAL Receiver -->
<receiver
android:exported="true"
android:name="receivers.DialBroadcastReceiver" >
<intent-filter >
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
You need Permission for NEW_OUTGOING_CALL :
<!-- OUTGOING CALL PERMISSION-->
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
Eventually you can Receive the broadcast and retrieve the dialed number like this:
public class DialBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.v("DileBroadCastReceiver","In onReceive()");
if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
Log.v("DialBroadcast Receiver","Number is: "+number);
}
}
}
I got my solution as following code
public class OutGoingCall extends BroadcastReceiver {
@Override
public void onReceive(final Context context, final Intent intent)
{
// get phone number from bundle
String phoneNumber = intent.getExtras().getString(OutGoingCall.INTENT_PHONE_NUMBER);
}
}
来源:https://stackoverflow.com/questions/9909153/how-to-get-dialed-mobile-number-in-my-application