Android获取设备信息
2017-08-23 17:19
429 查看
package com.yjdgis.mobile.command;
import android.content.Context;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.util.Log;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
/**
* Created by Admin on 2017/6/17.
*/
public class DeviceInfo {
public static String getDeviceIMEI(Context curContext) {
String device = "unknown";
try {
TelephonyManager tm = (TelephonyManager) curContext.getSystemService(Context.TELEPHONY_SERVICE);
device = tm.getDeviceId();
getDeviceIMSI(curContext);
} catch (Exception ex) {
Log.e("GetDeviceID", ex.getMessage() + "");
}
return device;
}
public static String getDeviceIMSI(Context curContext) {
TelephonyManager tm = (TelephonyManager) curContext.getSystemService(Context.TELEPHONY_SERVICE);
String phoneNumber = tm.getLine1Number();
Log.i("Line1Number", phoneNumber + "");
/*
* 服务商名称,例如:中国移动、联通,SIM卡的状态必须是 SIM_STATE_READY(使用getSimState()判断).
*/
String soname= tm.getSimOperatorName();//String
Log.i("SimOperatorName", soname + "");
/*
* SIM卡的序列号:* 需要权限:READ_PHONE_STATE
*/
String ssn= tm.getSimSerialNumber();//String
Log.i("SimSerialNumber", ssn + "");
/*
* 唯一的用户ID,例如:IMSI(国际移动用户识别码) for a GSM phone.
* 需要权限:READ_PHONE_STATE
*/
String imsi = tm.getSubscriberId();
Log.i("imsi", imsi + "");
return imsi;
}
public static String getIPAddress(Context curContext) {
WifiManager wifi = (WifiManager) curContext.getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wifi.getConnectionInfo();
info.getIpAddress();
return "";
}
public static String getAndroidID(Context curContext) {
String systemid = Settings.Secure.getString(curContext.getContentResolver(), Settings.Secure.ANDROID_ID);
String name = Settings.Secure.getString(curContext.getContentResolver(), Settings.Secure.NAME);
return systemid;
}
public static String getMacAddress(Context curContext) {
WifiManager wifi = (WifiManager) curContext.getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wifi.getConnectionInfo();
info.getIpAddress();
return info.getMacAddress();
}
public static String getDeviceModel()//设备型号
{
String device_model = Build.MODEL;
String version_release = Build.VERSION.RELEASE;//系统版本;
String version_sdk = Build.VERSION.SDK_INT + ""; // 设备SDK版本
String a = Build.DEVICE.toString();
return device_model;
}
public static String getCPUSerial() {
String str = "", strCPU = "", cpuAddress = "0000000000000000";
try {
//读取CPU信息
Process pp = Runtime.getRuntime().exec("cat /proc/cpuinfo");
InputStreamReader ir = new InputStreamReader(pp.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
//查找CPU序列号
for (int i = 1; i < input.getLineNumber(); i++) {
str = input.readLine();
if (str != null) {
//查找到序列号所在行
if (str.indexOf("Serial") > -1) {
//提取序列号
strCPU = str.substring(str.indexOf(":") + 1, str.length());
cpuAddress = strCPU.trim();
break;
}
} else {
//文件结尾
break;
}
}
} catch (IOException ex) {
//赋予默认值
ex.printStackTrace();
}
return cpuAddress;
}
}
相关文章推荐
- Android 获取唯一设备号和机型信息
- Android 获取设备网卡信息
- Android获取设备ID、型号及其它信息
- android 系统版本信息工具类 获取设备型号 设置屏幕亮度 软键盘 获取屏幕高度宽度
- TelephonyManager的介绍 & Android获取SIM卡信息、设备信息
- android 获取设备Configuration配置信息
- Android 获取设备各种信息以及其它
- Android获取设备的基本服务信息
- 写python获取android设备的GPS及姿态信息
- Android 获取唯一设备号和机型信息
- android 获取设备信息
- android 安卓APP获取手机设备信息和手机号码的代码示例
- Android 获取设备各种信息以及其它
- Android获取设备信息
- Android获取设备或应用基本信息
- Android通过反射的方法获取手机存储设备的状态信息
- 获取android 设备的cpu gpu信息 mac地址
- android 获取设备Configuration配置信息
- Android 获取手机设备信息、网络信息、SIM卡信息
- Android上获取设备的信息