写点什么

Android 获取设备信息

用户头像
Android架构
关注
发布于: 1 小时前

TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);


if (tm == null) {


return "";


}


return "" + tm.getSimSerialNumber();


}


//IMSI


public static String getSubscriberId(Context context) {


TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);


if (tm == null) {


return "";


}


return "" + tm.getSubscriberId();


}


//sim 卡所在国家


public static String getNetworkCountryIso(Context context) {


TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);


if (tm == null) {


return "";


}


return "" + tm.getNetworkCountryIso();


}


//运营商编号。


public static String getNetworkOperator(Context context) {


TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);


if (tm == null) {


return "";


}


return tm.getNetworkOperator();


}


//android 获取当前手机型号


public static String getPhoneModel(Context context) {


Build bd = new Build();


return bd.MODEL;


}


//android 获取当前手机品牌


public static String getPhoneProduct(Context context) {


Build bd = new Build();


return bd.PRODUCT;


}


//android 获取屏幕分辩率


public static String getMetrics(Context context) {


DisplayMetrics dm = new DisplayMetrics();


int h = dm.heightPixels;


int w = dm.widthPixels;


return h+ "*" +w;


}


//android 获取当前时区


public static String getTimeZone(Context context) {


TimeZone tz = TimeZone.getDefault();


String s = tz.getID();


System.out.println(s);


return s;


}


//android 获取当前日期时间


public static String getDateAndTime(Context context) {


SimpleDateFormat formatter = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss");


Date curDate = new Date(System.currentTimeMillis());//获取当前时间


String str = formatter.format(curDate);


return str;


}


//获取手机系统语言 0 中文简体 1 其它


public static String getLanguage(Context context) {


Locale locale = context.getResources().getConfiguration().locale;


String language = locale.getLanguage();


if (language.endsWith("zh"))


return "0";


else


return "1";


}


/**


  • 获取网络类型


*/


public static int getNetWorkType(Context context) {


ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);


NetworkInfo networkInfo = manager.getActiveNetworkInfo();


if (networkInfo != null && networkInfo.isConnected()) {


String type = networkInfo.getTypeName();


if (type.equalsIgnoreCase("WIFI")) {


return AVConstants.NETTYPE_WIFI;


} else if (type.equalsIgnoreCase("MOBILE")) {


NetworkInfo mobileInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);


if (mobileInfo != null) {


switch (mobileInfo.getType()) {


case ConnectivityManager.TYPE_MOBILE:// 手机网络


switch (mobileInfo.getSubtype()) {


case TelephonyManager.NETWORK_TYPE_UM


《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》
浏览器打开:qq.cn.hn/FTe 免费领取
复制代码


TS:


case TelephonyManager.NETWORK_TYPE_EVDO_0:


case TelephonyManager.NETWORK_TYPE_EVDO_A:


case TelephonyManager.NETWORK_TYPE_HSDPA:


case TelephonyManager.NETWORK_TYPE_HSUPA:


case TelephonyManager.NETWORK_TYPE_HSPA:


case TelephonyManager.NETWORK_TYPE_EVDO_B:


case TelephonyManager.NETWORK_TYPE_EHRPD:


case TelephonyManager.NETWORK_TYPE_HSPAP:


return AVConstants.NETTYPE_3G;


case TelephonyManager.NETWORK_TYPE_CDMA:


case TelephonyManager.NETWORK_TYPE_GPRS:


case TelephonyManager.NETWORK_TYPE_EDGE:


case TelephonyManager.NETWORK_TYPE_1xRTT:


case TelephonyManager.NETWORK_TYPE_IDEN:


return AVConstants.NETTYPE_2G;


case TelephonyManager.NETWORK_TYPE_LTE:


return AVConstants.NETTYPE_4G;


default:


return AVConstants.NETTYPE_NONE;


}


}


}

用户头像

Android架构

关注

还未添加个人签名 2021.10.31 加入

还未添加个人简介

评论

发布
暂无评论
Android 获取设备信息