核心代码:
Imei = ((TelephonyManager) getSystemService(TELEPHONY_SERVICE))
.getDeviceId();
1.加入权限
在manifest.xml文件中要添加
2.代码
/**
*
*
*创建日期 2010-4-29 下午05:02:47
*
*/
package net.sunniwell.app;
import android.app.Activity;
import android.os.Bundle;
import android.telephony.CellLocation;
import android.telephony.PhoneStateListener;
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);
/*
* 电话状态:
* 1.tm.CALL_STATE_IDLE=0 无活动
* 2.tm.CALL_STATE_RINGING=1 响铃
* 3.tm.CALL_STATE_OFFHOOK=2 摘机
*/
tm.getCallState();//int
/*
* 电话方位:
*
*/
tm.getCellLocation();//CellLocation
/*
* 唯一的设备ID:
* GSM手机的 IMEI 和 CDMA手机的 MEID.
* Return null if device ID is not available.
*/
tm.getDeviceId();//String
/*
* 设备的软件版本号:
* 例如:the IMEI/SV(software version) for GSM phones.
* Return null if the software version is not available.
*/
tm.getDeviceSoftwareVersion();//String
/*
* 手机号:
* GSM手机的 MSISDN.
* Return null if it is unavailable.
*/
tm.getLine1Number();//String
/*
* 附近的电话的信息:
* 类型:List
* 需要权限:android.Manifest.permission#ACCESS_COARSE_UPDATES