简体   繁体   English

Android imei号-如何选择?

[英]Android imei number - how to pick it?

developed an app using a mobile phone used this code to pick imei number 使用手机开发了一个应用,使用此代码选择了imei号

Utill.class

static TelephonyManager telephonyManager;
public static String getDeviceID(){
telephonyManager=(TelephonyManager) MyApplication.getInstance().getSystemService(MyApplication.getInstance().TELEPHONY_SERVICE);

        return telephonyManager.getDeviceId();

    }

in my job.class

String imeino = Util.getDeviceID();

tested with mobile devises and it works properly but when apk installed a tab (in client side ) imei number does not pick and give a null pointer 使用移动设备进行了测试,并且可以正常工作,但是当apk安装了一个选项卡(在客户端)时,imei号无法选择并提供空指针

Note. 注意。 for tab i have added different layouts and it also works properly in my tab 对于选项卡,我添加了不同的布局,它也可以在我的选项卡中正常工作

is this a matter of base url or how can i avoid this issue of imei number ? 这是基本URL的问题还是我该如何避免这个imei number问题?

java Class and add following code java类并添加以下代码

TelephonyManager tel;
TextView imei;                
    tel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);        
    imei = (TextView) findViewById(R.id.textView2);
    imei.setText(tel.getDeviceId().toString());

AndroidManifest.xml and add following code AndroidManifest.xml并添加以下代码

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

Have this common method. 有这个通用的方法。 Devices without SIM slot will return null IMEI. 没有SIM卡插槽的设备将返回空IMEI。 So pick ANDROID_ID. 因此,选择ANDROID_ID。

public String getDeviceID(){ 
    String devcieId;   
    TelephonyManager mTelephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        if (mTelephony.getDeviceId() != null){
            devcieId = mTelephony.getDeviceId(); 
        }else{
             devcieId = Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID); 
        }
    return devcieId;
    }

Try this code it will return you IMEI number if device GSM based or if not get back the Android ID. 尝试使用此代码,如果设备基于GSM或未获取Android ID,它将返回您的IMEI号码。

String devcieId;   
    TelephonyManager mTelephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        if (mTelephony.getDeviceId() != null){
            devcieId = mTelephony.getDeviceId(); 
        }else{
             devcieId = Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID); 
        }

Also give the read phone state permission in your manifest. 同时在清单中授予阅读电话状态权限。

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM