在 Android 中获取我拨打的号码
我需要以编程方式从 Android 设备获取正在拨打的号码。我现在正在做的事情如下:
我监听 android.intent.action.PHONE_STATE
正在广播,这意味着我正在被呼叫或正在呼叫(或接收短信等)。
在 BroadcastReceiver
中,我从意图中检索额外的 incoming_number
。遗憾的是,如果我发起呼叫,我无法获得正在呼叫的号码。我该怎么做?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要使用 Intent
android.intent.action.NEW_OUTGOING_CALL
在此 Intent 中您可以获得额外的Intent.EXTRA_PHONE_NUMBER
其中包含呼出号码。如果发起新的拨出呼叫,则发出该意图。
为此,您需要权限
android.permission.PROCESS_OUTGOING_CALLS
。希望有帮助。
You need to use the Intent
android.intent.action.NEW_OUTGOING_CALL
in this intent you can get the extraIntent.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.