سؤال

I want to check Radio hardware equipped with my device or not.

How I get this information?

I use Build class to get radio information. But got crashed.

public final String SUPPORT = "Support";
public final String NOT_SUPPORT = "None";

public String checkRadio() {
    // Radio hardware has or not?

    if (Build.getRadioVersion() != null) {
        return SUPPORT;
    } else {
        return NOT_SUPPORT;
    }
}

Error:

08-22 15:49:46.662: E/AndroidRuntime(643): java.lang.NoSuchMethodError: android.os.Build.getRadioVersion
08-22 15:49:46.662: E/AndroidRuntime(643):  at com.mobilegenbg.deviceinfo.MainActivity.checkRadio(MainActivity.java:79)

Important: Build.Radio is deprecated.

any way?

هل كانت مفيدة؟

المحلول

That is deprecated.

You should consider reading the documentation again, specifically this part:

This field was deprecated in API level 14. The radio firmware version is frequently not available when this class is initialized, leading to a blank or "unknown" value for this string. Use getRadioVersion() instead.

Also:

getRadioVersion is for API 14 and later, it may return null as per this:

public static String getRadioVersion ()

Added in API level 14 Returns the version string for the radio firmware. May return null (if, for instance, the radio is not currently on).

Emphasis mine, unless you are running the code on older version of Android?

Or that the device is in Airplane mode or running on emulator?

Edit

If the getRadioVersion() call returns a non-null string, it may be "unknown" but did not return a null at least (Wrap it in a try/catch NullException block!).

That is dependent on the radio firmware and ROM, some may have that specified in the build.prop, others may not have it. Which in that case, the absence of it will yield "unknown". It is not reliable to use this call regardless as it varies from manufacturer to manufacturer and ROM dependent.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top