核心代碼:
Imei = ((TelephonyManager) getSystemService(TELEPHONY_SERVICE))
.getDeviceId();
1.加入權限
在manifest.xml檔案中要添加 <uses-permission android:name="android.permission.READ_PHONE_STATE" />
package com.jcrj.guidebook.ui;
import android.app.Activity;
import android.os.Bundle;
import android.telephony.TelephonyManager;
public class TelManager extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TelephonyManager tm = (TelephonyManager) this.getSystemService(TELEPHONY_SERVICE);
tm.getCallState();// int
tm.getCellLocation();// CellLocation
tm.getDeviceId();// String
tm.getDeviceSoftwareVersion();// String
tm.getLine1Number();// String
tm.getNeighboringCellInfo();// List<NeighboringCellInfo>
tm.getNetworkCountryIso();// String
tm.getNetworkOperator();// String
tm.getNetworkOperatorName();// String
tm.getNetworkType();// int
tm.getPhoneType();// int
tm.getSimCountryIso();// String
tm.getSimOperator();// String
tm.getSimOperatorName();// String
tm.getSimSerialNumber();// String
tm.getSimState();// int
tm.getSubscriberId();// String
tm.getVoiceMailAlphaTag();// String
tm.getVoiceMailNumber();// String
tm.hasIccCard();// boolean
tm.isNetworkRoaming();//
}
}