2013-02-02 84 views
17

我想通过编程注册配置我的应用程序以及我的应用程序已安装在其上的用户和电话的数量来获取电话序列号。如何获取电话序列号(IMEI)

我能明白吗?

我可以得到手机型号,我的应用程序已安装在他们身上?

+1

要获得IMEI号码使用此代码 'TelephonyManager mngr = getSystemService(Context.Telephony_service); mngr.getDeviceId()' – techieWings

+0

哪些权限需要? –

+0

READ_PHONE_STATE – techieWings

回答

60

请参阅本 https://stackoverflow.com/a/1972404/951045

TelephonyManager mngr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); 
    mngr.getDeviceId(); 

添加READ_PHONE_STATE权限AndroidManifest.xml

+2

Context.Telephony_service ---> Context.TELEPHONY_SERVICE – ChangUZ

+0

您可以使用: TelephonyManager tManager =(TelephonyManager)myActivity.getSystemService(Context.TELEPHONY_SERVICE); String uid = tManager.getDeviceId(); –

+0

对于Android M及以上版本,用户可能不会授予权限,因此在访问它们之前我们需要检查相同的权限。看看这个答案http://stackoverflow.com/a/38782876/3811068 –

3

下面是代码: -

telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); 


    deviceId = telephonyManager.getDeviceId(); 
    Log.d(TAG, "getDeviceId() " + deviceId); 



    phoneType = telephonyManager.getPhoneType(); 
    Log.d(TAG, "getPhoneType() " + phoneType); 
0

试试这个

final TelephonyManager tm =(TelephonyManager)getBaseContext().getSystemService(Context.TELEPHONY_SERVICE); 

    String deviceid = tm.getDeviceId(); 
9
public String getIMEI(Context context){ 

    TelephonyManager mngr = (TelephonyManager) context.getSystemService(context.TELEPHONY_SERVICE); 
    String imei = mngr.getDeviceId(); 
    return imei; 

} 
0

下面的代码使用IMEI:

TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE); 
String imei= tm.getDeviceId();