Android Device phone call ability

前端 未结 7 914
粉色の甜心
粉色の甜心 2020-12-02 23:09

How can I tell whether a given device has the ability to make phone calls?

For example, my Galaxy Tablet cannot initiate call, its not a phone. I want to detect tha

7条回答
  •  攒了一身酷
    2020-12-02 23:32

    if (((TelephonyManager)getContext().getSystemService(Context.TELEPHONY_SERVICE)).getPhoneType()
        == TelephonyManager.PHONE_TYPE_NONE)
    {
        // no phone
    }
    

    EDIT I'm surprised it comes back PHONE_TYPE_CDMA. Here's another possibility:

    if (((TelephonyManager)getContext().getSystemService(Context.TELEPHONY_SERVICE)).getLine1Number()
        == null)
    {
        // no phone
    }
    

    This will require the READ_PHONE_STATE permission.

提交回复
热议问题