Android How to check call functionality for device / tablet support

There is a call function in my application. When you click the Call button, the application will launch a phone number with a phone number.

Now, if any device / tablet does not have a call function, in this case I want to check this

if(isSupportCalling) 
      //launch dialer
else 
     //show message

to avoid application crash.

Since this permission only allows android to make it visible and able to download / install the application on a device / tablet that does not support call functionality.

<uses-feature 
        android:name="android.hardware.telephony" 
        android:required="false"/>

Since I have seen very few SO threads related to this, but have not found a reliable way to do this.

+5
source share
2 answers

TelephonyManager, , , .

TelephonyManager tm= (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
       if(tm.getPhoneType()==TelephonyManager.PHONE_TYPE_NONE){
        //No calling functionality
       }
       else
       {
       //calling functionality
       }

,

+8

:

:

 private boolean canMakeCalls(){
    return ((TelephonyManager)getActivity().getSystemService(Context.TELEPHONY_SERVICE)).getLine1Number()
    != null;
}

, :

  if (canMakeCalls()){}

,

+2

All Articles