简体   繁体   English

我可以获取通过本机拨号程序拨打的号码吗?

[英]Can I get the number that is calling by native dialer?

Can I get the number that is calling by native dialer ? 我可以获取通过本机拨号程序拨打的号码吗?

I want to show the "toast message" with information about cost per minute according to a dialing number. 我想显示“吐司消息”,其中包含根据拨号号码的每分钟费用信息。 But I do not know how to get this number. 但是我不知道如何获得这个号码。

It could be good to have sample which show "toast message" with dialed number during of call. 最好在呼叫过程中显示带有拨号号码的“ toast消息”的样本。

yes you can do it.You need to implement PhoneStateListener 是的,您可以做到。您需要实现PhoneStateListener

public class CustomPhoneStateListener extends PhoneStateListener { 公共类CustomPhoneStateListener扩展了PhoneStateListener {

public static Boolean phoneRinging = false;

public void onCallStateChanged(int state, String incomingNumber) {

    switch (state) {
    case TelephonyManager.CALL_STATE_IDLE:
        Log.d("DEBUG", "IDLE");
        phoneRinging = false;
        break;
    case TelephonyManager.CALL_STATE_OFFHOOK:
        Log.d("DEBUG", "OFFHOOK");
        phoneRinging = false;
        break;
    case TelephonyManager.CALL_STATE_RINGING:
        Log.d("DEBUG", "RINGING");
        phoneRinging = true;

        break;
    }
}

} }

To register the listener do this: 要注册侦听器,请执行以下操作:

        CustomPhoneStateListener phoneListener = new CustomPhoneStateListener();
        telephony = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);
        telephony.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);

Note that access to some telephony information is permission-protected. 请注意,访问某些电话信息受权限保护。 Your application won't receive updates for protected information unless it has the appropriate permissions declared in its manifest file. 除非您的应用程序具有清单文件中声明的适当权限,否则它将不会收到有关受保护信息的更新。 Where permissions apply, they are noted in the appropriate LISTEN_ flags. 在适用权限的情况下,它们会在相应的LISTEN_标志中注明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM