Dismissile Dismissile - 1 month ago 7
AngularJS Question

Detect tablet in ionic app

I am working on an ionic app and we have a button to Call someone. This doesn't make a whole lot of sense when using a tablet so I would like to not show this button if the person is using a tablet.

Is there an easy way using ionic/cordova that I can detect if the device is a tablet (or I suppose I could also detect if the device has a phone application)?

Answer Source

You can see how call feature detection is done in CordovaCallNumberPlugin. There are tablets which support calling so I would check for this, but this is of course up to you and depends on your application.

Android:

private boolean isTelephonyEnabled(){
    TelephonyManager tm = (TelephonyManager)cordova.getActivity().getSystemService(Context.TELEPHONY_SERVICE);

    return tm != null && tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE;
}

iOS:

if(![[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:number]]) {
    pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"NoFeatureCallSupported"];
}