2013-02-02 81 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();