Question

The documented way to detect presence of the telephony module on android is to check FEATURE_TELEPHONY feature. Unfortunately on some smartphones and on emulator the check returns false even when the phone is present. So it's not a reliable way as it gives false negatives.

I've found a way to obtain telephony manager (TelephonyManager tm=(TelephonyManager )this.getSystemService(Context.TELEPHONY_SERVICE); but it gives false positive at least on Nexus 7 tablet.

My goal is to hide options related to phone calls and SMS sending from my widget, if those phone calls or SMS sending are not possible.

Does the reliable method to solve my task exist on Android 2.2 and later?

Was it helpful?

Solution

(TelephonyManager tm=(TelephonyManager )this.getSystemService(Context.TELEPHONY_SERVICE);

I don't know why above code is returning false positive, but why don't you check its network type or network operator with telephony manager? For example, it might be returning NETWORK_TYPE_UNKNOWN flag for nexus 7.

return (android.telephony.TelephonyManager.getNetworkType()
    != android.telephony.TelephonyManager.NETWORK_TYPE_UNKNOWN)

Refernce:

OTHER TIPS

I am doing this using Intent resolution, as follows:

// Prepare the intent.
theIntent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:3334444"));

// Resolve the activity for the desired intent.
theResolveInfo = thePM.resolveActivity(theIntent, 
                                       PackageManager.MATCH_DEFAULT_ONLY);

Testing on Nexus 7 properly indicated that call ability is not present.

Testing on Genymotion emulator indicated that call ability is present.

Have not yet tested other devices.

After giving it some thought, I think it would be sufficient to determine whether the device is capable of sending an SMS.

You can use the SMSSender from my answer to: Send SMS until it is successful

Then send and SMS to some predefined number, does not really matter what the number is as long as you do not use any existing numbers and bother a random person :P '

Lastly register for the SENT broadcast.

If the SMS is sent, then device has radio capability, otherwise not, so simply turn on these options if the message is sent.

I know, though, that if the device for some reason is offline while performing this check, then it will believe it cannot make calls or send SMS.

Just to give you another option than TelephonyManager.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top