本文介绍了如何从来电得到的电话号码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获得的电话号码,当有来电在Android的?
How do I get the phone number when there is an incoming call in Android?
推荐答案
请在广播接收器
说 ServiceReceiver
分配其清单行动。
Make a Broadcast receiver
say ServiceReceiver
assign its action in Manifest.
<receiver android:name=".ServiceReceiver" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
在 PhoneStateListener
添加到您的TelephonyManager,其覆盖PhoneStateListener onCallStateChanged()
与来电号码的参数。这就是它。
Add a PhoneStateListener
to your TelephonyManager, PhoneStateListener having override onCallStateChanged()
with Incoming number parameter. Thats it.
ServiceReceiver.Java
public class ServiceReceiver extends BroadcastReceiver {
@Override
public void onReceive(final Context context, Intent intent) {
TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
telephony.listen(new PhoneStateListener(){
@Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
System.out.println("incomingNumber : "+incomingNumber);
}
},PhoneStateListener.LISTEN_CALL_STATE);
}
这篇关于如何从来电得到的电话号码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!