Get the number I am calling in Android

百般思念 提交于 2019-12-22 00:35:13

问题


I need to get the number that I am calling from my Android device programmatically. What I'm doing now is the following:

I listen for android.intent.action.PHONE_STATE being broadcasted which means that either I am being called or am calling (or receiving an SMS etc).

In a BroadcastReceiver I retrieve the extra incoming_number from the intent. Sadly I cannot get the number which is being called if I initiate the call though. How can I do this?


回答1:


You need to use the Intent android.intent.action.NEW_OUTGOING_CALL in this intent you can get the extra Intent.EXTRA_PHONE_NUMBER which contains the outgoing number.

The intent is issued if a new outgoing call is intanciated.

You will need the Permission android.permission.PROCESS_OUTGOING_CALLS for this.

Hope that helps.




回答2:


@Override
public void onReceive(Context context, Intent intent) {
    String phonenumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
    Log.d("OutgoingCallReceiver",phonenumber);
    Log.d("OutgoingCallReceiver",intent.getExtras().toString());
}


来源:https://stackoverflow.com/questions/5337054/get-the-number-i-am-calling-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!