Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android How to check device/tablet support calling functionality

Tags:

android

In my app there is a calling functionality. On click of "Call" button, app will launch the phone dialer with phone number.

Now if any of the device/tablet is not having the calling functionality, in that case i want to check this

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

inorder to avoid any application crash.

As this permission will only allow android play to make it visible and able to download/install the app on device/tablet which don't support calling functionality.

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

As i had seen very few threads on SO related to this, but didn't find a reliable way to this.

like image 595
amsiddh Avatar asked Jun 14 '12 07:06

amsiddh


2 Answers

By using TelephonyManager class, you can tell the availability of phone network as well as you can check for different related state of phone network.

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

Hope This Helps

like image 137
Sarim Sidd Avatar answered Nov 08 '22 08:11

Sarim Sidd


That's it:

You should do the following:

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

and just call the function whenever you want:

  if (canMakeCalls()){}

Hope that helps

like image 42
arniotaki Avatar answered Nov 08 '22 06:11

arniotaki