您的位置:首页 > 移动开发 > Android开发

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 设备信息