Is this a correct way of checking whether a device can make a call?

I need to test whether the device running my app can make a call. The code below returns the expected result on my limited number of physical devices, but I wonder if there are cases that this does not handle. Can anybody see any flaws?

    public bool CanDial()
        // we use ActionCall here rather than ActionDial, as ActionDial can return
        // a component that handles Contacts but not Telephony. However, note that
        // ActionCall not returning an activity here does not mean that there is
        // no telephony, which is why there is other logic below.

        Intent intent = new Intent(Intent.ActionCall);
        ComponentName componentName = intent.ResolveActivity(Forms.Context.PackageManager);
        if (componentName != null)
            return true;

        Android.Content.PM.FeatureInfo[] v = Forms.Context.PackageManager.GetSystemAvailableFeatures();
        foreach (Android.Content.PM.FeatureInfo fi in v)
            if (fi != null)
                // It seems odd, but Name can be null here
                if ((fi.Name != null) && fi.Name.ToLower().Contains("telephon"))
                    return true;

        return false;

Many thanks,

John H.

Sign In or Register to comment.