如何找出android设备是否具有蜂窝无线电模块? [英] How to find out whether android device has cellular radio module?

查看:184
本文介绍了如何找出android设备是否具有蜂窝无线电模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何确定该设备确实具有gsm,cdma或其他蜂窝网络设备(不仅仅是WiFi)? 我不想检查当前连接的网络状态,因为该设备目前可能处于离线状态. 而且我不想通过((TelephonyManager)act.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId()检查设备ID,因为某些设备只会为您提供多态或虚拟设备ID.

How can I find out for sure that device really has gsm, cdma or other cellular network equipment (not just WiFi)? I don't want to check current connected network state, because device can be offline in the moment. And I don't want to check device id via ((TelephonyManager) act.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId() because some devices would just give you polymorphic or dummy device ID.

准确地说,我需要检查一下蜂窝设备以跳过TelephonyManager.getDeviceId并在那些没有蜂窝无线电的设备上执行Settings.Secure.ANDROID_ID检查.我至少有一个平板电脑("Storage Options Scroll Excel 7"),每次您询问时,它都会返回不同的IMEI,尽管它应该返回null,因为它没有手机广播(这里的情况相同:

Actualy, I need to check cell equipment exactly for skipping TelephonyManager.getDeviceId and performing Settings.Secure.ANDROID_ID check on those devices that don't have cellular radio. I have at least one tablet (Storage Options Scroll Excel 7") which returns different IMEIs every time you ask it, although it should return null as it has no cell radio (the same situation here: Android: getDeviceId() returns an IMEI, adb shell dumpsys iphonesubinfo returns Device ID=NULL). But I need to have reliable device id that is the same every time I ask.

很高兴听到您的想法!

推荐答案

以防万一有人需要完整的解决方案: 使用反射是因为某些固件版本上可能不存在某些内容. MainContext-主要活动上下文.

Just in case somebody needs complete solution for this: Reflection is used because some things may not exist on some firmware versions. MainContext - main activity context.

    static public int getSDKVersion()
{
    Class<?> build_versionClass = null;

    try
    {
        build_versionClass = android.os.Build.VERSION.class;
    }
    catch (Exception e)
    {
    }

    int retval = -1;
    try
    {
        retval = (Integer) build_versionClass.getField("SDK_INT").get(build_versionClass);
    }
    catch (Exception e)
    {
    }

    if (retval == -1)
        retval = 3; //default 1.5

    return retval;
}

static public boolean hasTelephony()
{
    TelephonyManager tm = (TelephonyManager) Hub.MainContext.getSystemService(Context.TELEPHONY_SERVICE);
    if (tm == null)
        return false;

    //devices below are phones only
    if (Utils.getSDKVersion() < 5)
        return true;

    PackageManager pm = MainContext.getPackageManager();

    if (pm == null)
        return false;

    boolean retval = false;
    try
    {
        Class<?> [] parameters = new Class[1];
        parameters[0] = String.class;
        Method method = pm.getClass().getMethod("hasSystemFeature", parameters);
        Object [] parm = new Object[1];
        parm[0] = "android.hardware.telephony";
        Object retValue = method.invoke(pm, parm);
        if (retValue instanceof Boolean)
            retval = ((Boolean) retValue).booleanValue();
        else
            retval = false;
    }
    catch (Exception e)
    {
        retval = false;
    }

    return retval;
}

这篇关于如何找出android设备是否具有蜂窝无线电模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆