Android 获取设备ID,手机厂商,运营商,联网方式,获取系统语言,获取时区

权限

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

安卓6.0需动态获取权限:Android 6.0及以上版本动态申请权限_meixi_android的博客-CSDN博客

获取设备ID

方法1

private String getAndroidId(){String m_szAndroidID = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);return m_szAndroidID;
}
deviceId = Settings.System.getString(sInstance.getContentResolver(), Settings.Secure.ANDROID_ID);

方法2

String serialNum = android.os.Build.SERIAL;

方法3

String model = "";
TelephonyManager tm = (TelephonyManager) getSystemService(Activity.TELEPHONY_SERVICE);if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling//    ActivityCompat#requestPermissions// here to request the missing permissions, and then overriding//   public void onRequestPermissionsResult(int requestCode, String[] permissions,//                                          int[] grantResults)// to handle the case where the user grants the permission. See the documentation// for ActivityCompat#requestPermissions for more details.return;
}
model = tm.getDeviceId();
Log.i("lgq","ssssssssssss===== "+model);

 方法4:

private String getImei(){TelephonyManager TelephonyMgr = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);String szImei = TelephonyMgr.getDeviceId();return szImei;
}

Android 系统 5.0 以下的。方法3/4无效

结果是:

11-05 16:38:46.860 17570-17570/com.tianxin.jifei I/lgq: ssssssssssss===== 862266036040933

获取联网方式:

String access = "";
ConnectivityManager connectionManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo netWorkInfo = connectionManager.getActiveNetworkInfo();
access = netWorkInfo.getTypeName();Log.i("lgq","ssssssssssss===== "+access);

结果是:

11-05 16:52:49.300 18844-18844/com.tianxin.jifei I/lgq: ssssssssssss===== WIFI

11-05 16:53:02.106 19425-19425/com.tianxin.jifei I/lgq: ssssssssssss===== MOBILE

  获取操作系统版本:

/获取操作系统版本String osVersion = "";osVersion = android.os.Build.VERSION.RELEASE;

获取运营商:

String providersName = "";
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {// TODO: Consider calling//    ActivityCompat#requestPermissions// here to request the missing permissions, and then overriding//   public void onRequestPermissionsResult(int requestCode, String[] permissions,//                                          int[] grantResults)// to handle the case where the user grants the permission. See the documentation// for ActivityCompat#requestPermissions for more details.return;
}
String IMSI = telephonyManager.getSubscriberId();
if (IMSI != null) {if (IMSI.startsWith("46000") || IMSI.startsWith("46002") || IMSI.startsWith("46007")) {providersName = "中国移动";} else if (IMSI.startsWith("46001") || IMSI.startsWith("46006")) {providersName = "中国联通";} else if (IMSI.startsWith("46003")) {providersName = "中国电信";} else {providersName = "其他";}
} else {providersName = "无法获取运营商信息";
}

手机厂商:

String ss= android.os.Build.MANUFACTURER;

 附:

android.os.Build.BOARD:获取设备基板名称
android.os.Build.BOOTLOADER:获取设备引导程序版本号
android.os.Build.BRAND:获取设备品牌
android.os.Build.CPU_ABI:获取设备指令集名称(CPU的类型)
android.os.Build.CPU_ABI2:获取第二个指令集名称
android.os.Build.DEVICE:获取设备驱动名称
android.os.Build.DISPLAY:获取设备显示的版本包(在系统设置中显示为版本号)和ID一样
android.os.Build.FINGERPRINT:设备的唯一标识。由设备的多个信息拼接合成。
android.os.Build.HARDWARE:设备硬件名称,一般和基板名称一样(BOARD)
android.os.Build.HOST:设备主机地址
android.os.Build.ID:设备版本号。
android.os.Build.MODEL :获取手机的型号 设备名称。
android.os.Build.MANUFACTURER:获取设备制造商
android:os.Build.PRODUCT:整个产品的名称
android:os.Build.RADIO:无线电固件版本号,通常是不可用的 显示unknown
android.os.Build.TAGS:设备标签。如release-keys 或测试的 test-keys 
android.os.Build.TIME:时间
android.os.Build.TYPE:设备版本类型  主要为"user" 或"eng".
android.os.Build.USER:设备用户名 基本上都为android-build
android.os.Build.VERSION.RELEASE:获取系统版本字符串。如4.1.2 或2.2 或2.3等
android.os.Build.VERSION.CODENAME:设备当前的系统开发代号,一般使用REL代替
android.os.Build.VERSION.INCREMENTAL:系统源代码控制值,一个数字或者git hash值
android.os.Build.VERSION.SDK:系统的API级别 一般使用下面大的SDK_INT 来查看
android.os.Build.VERSION.SDK_INT:系统的API级别 数字表示
 

获取系统语言

Locale locale = Locale.getDefault();
Log.e("lgq","..... "+locale.getCountry().toLowerCase());
Log.e("lgq","..... "+locale.getLanguage());
Log.e("lgq","..... "+locale);

获取时区

//获取当前时区
public static int getTzSec() {Date date = new Date();//取得本地时间Calendar cal = Calendar.getInstance();//取得时间偏移量int offset = cal.get(Calendar.ZONE_OFFSET) / (1000 * 60 * 60);//取得夏令时差int dstOffset = cal.get(Calendar.DST_OFFSET) / (1000 * 60 * 60);//从本地时间里扣除这些变量,即可以取得UTC时间cal.add(Calendar.MILLISECOND, -(offset + dstOffset));cal.add(Calendar.HOUR, -(offset + dstOffset));Long timeStampUTC = cal.getTimeInMillis();Long timeStamp = date.getTime();Long timeZone = (timeStamp - timeStampUTC) / (1000 * 3600);return timeZone.intValue();
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/414998.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

str和unicode类

在py2中&#xff0c;分为两类&#xff0c;str和unicode 而在py3中&#xff0c;分为两类&#xff0c;byte和str py2中的str等同于py3中的byte 首先明确一点&#xff0c;我们编辑好一段文本&#xff0c;python并不知道我们的文本是以什么格式编码的。如果是纯英文字符还好说&…

Android 带阴影背景图片

1、添加依赖 compile com.dingmouren.paletteimageview:paletteimageview:1.0.7 2、引用 <com.dingmouren.paletteimageview.PaletteImageViewandroid:id"id/palette"android:layout_width"400dp"android:layout_height"400dp"android:lay…

Android画板控件,可以写字,签名,画画并生成图片

1效果图 实现步骤 1、添加画板控件module 画板控件module下载&#xff1a;https://download.csdn.net/download/meixi_android/10774781 2、xml文件 <?xml version"1.0" encoding"utf-8"?> <LinearLayoutandroid:id"id/content_main&q…

【网络流24题】餐巾计划问题(最小费用最大流)

【网络流24题】餐巾计划问题&#xff08;最小费用最大流&#xff09; 题面 COGS 洛谷上的数据范围更大&#xff0c;而且要开longlong 题解 餐巾的来源分为两种&#xff1a; ①新买的 ②旧的拿去洗 所以&#xff0c;两种情况分别建图 先考虑第一种 因为新买餐巾没有任何限制&…

js正则表达式匹配span标签

1、js正则表达式匹配span标签 const spans htmlStr.match(/<span (.*?)>(.*?)<\/span>/g)2、js正则表达式–获取标签内的文本 function fn(str) {return str.match(/<span[^>]*>([\s\S]*?)<\/span>/)[1] }

工作209:整理订单的重置逻辑

1点击新增 2找到子组件下面的混入 3找到混入 4这一块或许就是重置逻辑

phaser设置图片资源大小

核心代码如下&#xff1a; // 加载图片资源 this.load.image(pic6, /images/phaser/img/pic6.png) const pic this.add.image(1505, 630, pic6) pic.displayWidth 100 pic.displayHeight 100

位域操作

看runtime源码时&#xff0c;看到如下声明变量的&#xff0c;变量后分号前加冒号和数字": 数字"即为位域操作。 uintptr_t indexed : 1; 1个字节包含8位&#xff0c;有些变量保存的数据不需要占用这么长的空间&#xff08;比如bool类型&#xff0c;只有两个…

工作211:新的封装组件 秒呀

<!-- 可以动态新增的 tag 列表 --> <template><div><el-tagv-for"(tag, index) in dynamicTags":key"index":closable"true":disable-transitions"false"close"handleClose(tag)">{{ tag }}</el…

HTTP协议简介,数据安全 如何保证http传输安全性,http与https区别

目前大多数网站和app的接口都是采用http协议&#xff0c;但是http协议很容易就通过抓包工具监听到内容&#xff0c;甚至可以篡改内容&#xff0c;为了保证数据不被别人看到和修改&#xff0c;可以通过以下几个方面避免。 重要的数据&#xff0c;要加密&#xff0c;比如用户名密…

mongoose只更新数组中某一项的字段

只是需要一个特殊符号$代表匹配某一项 数据库设计如下&#xff1a; 核心代码如下&#xff1a; // 回答试题public async userPaperAnswer(request: IRequest, _h: IResponse) {const { user_paper_id, question_id, option_user } request.payload;const updOne await Use…

Koa2+Mysql搭建简易博客

http://blog.csdn.net/wclimb/article/details/77890793 转载于:https://www.cnblogs.com/SharkChilli/p/8177753.html

工作213:不能改变父组件值

父组件通过props传值给子组件&#xff0c;如何避免子组件改变props的属性值报错问题 报错Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop’s v…

uniapp移动H5在花生壳Invalid Host header

解决方案&#xff0c;在manifest.json中配置 "h5" : {"title" : "","domain" : "","devServer" : {"disableHostCheck" : true} }

Android 下拉式抽屉折叠动画

自定义listview工具类1、 public class ViewMeasureUtils {/*** 根据父 View 规则和子 View 的 LayoutParams&#xff0c;计算子类的宽度(width)测量规则** param view*/public static int getChildWidthMeasureSpec(View view, int parentWidthMeasureSpec) {// 获取父 View …

18.抽象模板方法———获取程序运行的时间

需求&#xff1a;获取一段程序运行的时间。原理&#xff1a;   获取程序开始和结束的额时间并相见即可  获取时间&#xff1a;System.currentTimeMillis(); 当代码完成优化后&#xff0c;就可以解决这类问题。这种方式&#xff0c;叫模板方法设计模式。 什么是模板方法呢&a…

js随机从数组中取出几个元素

这篇文章为转载&#xff0c;我的需求是从题库中&#xff0c;随机抽几道题&#xff0c;作为新试卷。代码如下&#xff1a; var items [1,2,4,5,6,7,8,9,10];1.从数组items中随机取出一个元素 var item items[Math.floor(Math.random()*items.length)];2.从前面的一篇随机数组…

工作214:结构 vue操作一个很有意思的报错 [Vue warn]: You may have an infinite update loop in a component

结构 vue操作一个很有意思的报错 [Vue warn]: You may have an infinite update loop in a component render function. 代码&#xff1a; <template><span class"show-filters" &#xff1a;class"show !show">{{ show ? 隐藏过滤器 ↑ …