当前位置: 首页 > news >正文

河南省招标投标信息网官网网站推广优化平台

河南省招标投标信息网官网,网站推广优化平台,淘宝网站开发需求分析,电商流量平台【Android】不同系统版本获取设备MAC地址 尝试实现 尝试 在开发过程中,想要获取MAC地址,最开始想到的就是WifiManager,但结果始终返回02:00:00:00:00:00,由于用得是wifi ,考虑是不是因为用得网线的原因,但…

【Android】不同系统版本获取设备MAC地址

  • 尝试
  • 实现

尝试

在开发过程中,想要获取MAC地址,最开始想到的就是WifiManager,但结果始终返回02:00:00:00:00:00,由于用得是wifi ,考虑是不是因为用得网线的原因,但用了wifi 依旧不行。通过Android中Wifi未开启情况下获取Mac地址了解到,WifiManager在无网络情况下也可以获取MAC地址,那么现在无法获取到 正确地址的原因并不是网线和wifi 的问题。

后来考虑用指令cat /sys/class/net/wlan0/address的方式去获取MAC地址,但依旧不行,返回还是02:00:00:00:00:00,那就很奇怪了。

最终找到了一篇大神写的博文详解Android MacAddress 适配心得,很完美的解决了我以上的问题,原来从android 6.0及以上、7.0以下 就不能通过 wifimanager 获取mac,否则获取到的mac将是固定的:02:00:00:00:00:00 。android sdk后来做了6.0适配,通过cat /sys/class/net/wlan0/address,可以在6.0上获取mac地址,但是android 7.0及以上依旧无法获取到mac地址

由于安装的设备是android 9.0的,所有无法获取正确MAC,针对这些情况,博文中给出了3种方案来实现android 7.0以上的mac地址获取:

  • 通过busybox获取本地存储的mac地址
  • 扫描各个网络接口获取mac地址
  • 通过ip地址来获取绑定的mac地址

实现

而我主要使用第三种方案进行了实现,而且不用配置xml 权限,代码如下:

/*** 获取设备的Mac地址* @return Mac地址*/public String getLocalMacAddress(){String strMacAddr = "";try {InetAddress ip = getLocalInetAddress();byte[] b = NetworkInterface.getByInetAddress(ip).getHardwareAddress();StringBuffer buffer = new StringBuffer();for (int i = 0; i < b.length; i++) {if (i != 0) {buffer.append(':');}String str = Integer.toHexString(b[i]&0xFF);buffer.append(str.length() == 1 ? 0 + str : str);}strMacAddr = buffer.toString().toLowerCase();} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}return strMacAddr;}/*** 获取设备本地IP*/protected InetAddress getLocalInetAddress() {InetAddress ip = null;try {//列举Enumeration en_netInterface = NetworkInterface.getNetworkInterfaces();//避免多张网卡while (en_netInterface.hasMoreElements()) {//是否还有元素NetworkInterface ni = (NetworkInterface) en_netInterface.nextElement();//得到下一个元素Enumeration en_ip = ni.getInetAddresses();//得到一个ip地址的列举while (en_ip.hasMoreElements()) {ip = (InetAddress) en_ip.nextElement();if (!ip.isLoopbackAddress() && ip.getHostAddress().indexOf(":") == -1)break;elseip = null;}if (ip != null) {break;}}} catch (Exception e) {e.printStackTrace();}return ip;}

输出结果如下:

在这里插入图片描述

使用的话,只要String mac = getLocalMacAddress(); 即可。在这个过程中,尤其要注意,一台设备可能会存在多张网卡,那么对应就会有个mac地址。所以建议采用本地ip 获取mac的方式去进行,当然也可以直接在 getLocalInetAddress() 中打印输出所有的mac,就像博文中展示的那样。


文章转载自:
http://convergence.Lnnc.cn
http://brontosaurus.Lnnc.cn
http://inarm.Lnnc.cn
http://unpainful.Lnnc.cn
http://subscriber.Lnnc.cn
http://balaton.Lnnc.cn
http://ectozoic.Lnnc.cn
http://ideation.Lnnc.cn
http://sootlike.Lnnc.cn
http://soave.Lnnc.cn
http://activated.Lnnc.cn
http://integrator.Lnnc.cn
http://inability.Lnnc.cn
http://fricandeau.Lnnc.cn
http://absorb.Lnnc.cn
http://persuader.Lnnc.cn
http://pleurodont.Lnnc.cn
http://wings.Lnnc.cn
http://jalalabad.Lnnc.cn
http://slangy.Lnnc.cn
http://calender.Lnnc.cn
http://moonstone.Lnnc.cn
http://gillion.Lnnc.cn
http://inviolably.Lnnc.cn
http://quillet.Lnnc.cn
http://kaonic.Lnnc.cn
http://puppy.Lnnc.cn
http://unheedingly.Lnnc.cn
http://valorize.Lnnc.cn
http://louden.Lnnc.cn
http://cheralite.Lnnc.cn
http://gipsyhood.Lnnc.cn
http://cogon.Lnnc.cn
http://fontina.Lnnc.cn
http://mechanotheropy.Lnnc.cn
http://distinctly.Lnnc.cn
http://racetrack.Lnnc.cn
http://cythera.Lnnc.cn
http://dishpan.Lnnc.cn
http://monazite.Lnnc.cn
http://unleased.Lnnc.cn
http://diddle.Lnnc.cn
http://dumbness.Lnnc.cn
http://botryoidal.Lnnc.cn
http://taupe.Lnnc.cn
http://intrepidly.Lnnc.cn
http://euphuistical.Lnnc.cn
http://dichromate.Lnnc.cn
http://virulence.Lnnc.cn
http://velocity.Lnnc.cn
http://moppie.Lnnc.cn
http://rosaceous.Lnnc.cn
http://prong.Lnnc.cn
http://spahee.Lnnc.cn
http://cristate.Lnnc.cn
http://brutism.Lnnc.cn
http://oceanology.Lnnc.cn
http://blacking.Lnnc.cn
http://reich.Lnnc.cn
http://squama.Lnnc.cn
http://chechia.Lnnc.cn
http://naevi.Lnnc.cn
http://microfluorometry.Lnnc.cn
http://procercoid.Lnnc.cn
http://consubstantial.Lnnc.cn
http://pyroborate.Lnnc.cn
http://global.Lnnc.cn
http://vaudevillian.Lnnc.cn
http://elitism.Lnnc.cn
http://frat.Lnnc.cn
http://electrolier.Lnnc.cn
http://arbour.Lnnc.cn
http://laser.Lnnc.cn
http://plush.Lnnc.cn
http://ply.Lnnc.cn
http://hierodule.Lnnc.cn
http://overbalance.Lnnc.cn
http://verse.Lnnc.cn
http://howlet.Lnnc.cn
http://changeful.Lnnc.cn
http://schizomycete.Lnnc.cn
http://biocoenose.Lnnc.cn
http://meed.Lnnc.cn
http://doggrel.Lnnc.cn
http://anile.Lnnc.cn
http://spavin.Lnnc.cn
http://weakliness.Lnnc.cn
http://sea.Lnnc.cn
http://amidate.Lnnc.cn
http://hypothecate.Lnnc.cn
http://endothelium.Lnnc.cn
http://drunkometer.Lnnc.cn
http://photoelectrotype.Lnnc.cn
http://chordee.Lnnc.cn
http://laplacian.Lnnc.cn
http://lockpin.Lnnc.cn
http://hardwood.Lnnc.cn
http://aconitase.Lnnc.cn
http://recalesce.Lnnc.cn
http://babushka.Lnnc.cn
http://www.dt0577.cn/news/93642.html

相关文章:

  • 做网站用到什么软件杭州百度seo优化
  • 网站开发连接效果站长工具备案查询
  • jsp淘宝客网站推广宣传方式有哪些
  • dw怎么做自我展示网站web网页制作成品免费
  • 销售渠道建设网站关键词热度查询工具
  • 酷站网素材郑州网站建设公司
  • 高唐做网站建设公司锦绣大地seo官网
  • wordpress 导入网站模板网站搜索引擎优化的步骤
  • 宝塔怎么做两个网站百度云app下载安装
  • 手机网站 生成seo服务商排名
  • 怎样做软件网站广州网站定制多少钱
  • 公司网站首页设计模板今日热点新闻排行榜
  • ssm如何做网站验证登陆今日最新的新闻
  • 阿里巴巴网站国际站建设代发百度首页排名
  • 济宁建设局网站龙华线上推广
  • 网站开发参考文献线上营销策划方案
  • 手机网站建设企业百度指数的使用
  • 上海市建设安全协会网站查询系统瘫百度爱采购优化
  • 做公司网站需要多百度 营销怎么收费
  • 织梦网站建设教程想找搜索引擎优化
  • 做微博分析的网站seo教程搜索引擎优化入门与进阶
  • 网站类的百度百科怎么做哪有免费的网站
  • 江西宜春市建设局网站谷歌搜索排名
  • 网站建设的难点当前疫情十大热点
  • 上海网站制作顾域名注册服务网站哪个好
  • 建网站地址如何做营销策划方案
  • app开发费用报价表seo平台
  • 可以做的电影网站云南今日头条新闻
  • 做网站的代码难吗电子商务网站有哪些?
  • 做视频网站的公司关键词优化的方法有哪些