问题一:Error:Error: The WIFI_SERVICE must be looked up on the Application context or memory will leak on de

android studio 移植的bug解决记录

解决:

eclipse到android studio的一些记录: 
1、Error: Your project contains C++ files but it is not using a supported native build system.

解决方案: 
如果没有grade.properties, 创建grade.properties 
grade.properties添加android.useDeprecatedNdk=true 
build.gradle添加sourceSets

  1. buildTypes
  2. {
  3. ...
  4. sourceSets
  5. {
  6. main
  7. {
  8. jni.srcDirs = []
  9. }
  10. }
  11. }

2、Error:(224) Error: The WIFI_SERVICE must be looked up on the Application context or memory will leak on devices < Android N. Try changing to .getApplicationContext() [WifiManagerLeak] 
解决方案: 
Android7 在获取 WifiManager的时候需要使用.getApplicationContext(),如果未使用会造成内存泄露。
原:

  1. WifiManager wifiMgr = (WifiManager) getSystemService(WIFI_SERVICE);

改:

  1. WifiManager wifiMgr = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);

3、Error:(3) Error: “app_name” is not translated in “en” (English) [MissingTranslation] 
解决方案: 
build.gradle添加配置

  1. android {
  2. ...
  3. lintOptions{
  4. checkReleaseBuilds false
  5. abortOnError false
  6. }
  7. }

4、Signature Version: V1(jar Signature) V2(full apk signature) 
Android 7.0中引入了APK Signature Scheme v2,v1呢是jar Signature来自JDK 
V1:应该是通过ZIP条目进行验证,这样APK 签署后可进行许多修改 - 可以移动甚至重新压缩文件。 
V2:验证压缩文件的所有字节,而不是单个 ZIP 条目,因此,在签名后无法再更改(包括 zipalign)。正因如此,现在在编译过程中,我们将压缩、调整和签署合并成一步完成。好处显而易见,更安全而且新的签名可缩短在设备上进行验证的时间(不需要费时地解压缩然后验证),从而加快应用安装速度。

问题二:Android6.0系统获getMacAddress()取Wifi和蓝牙Mac地址返回02:00:00:00:00:00解决办法

解决办法:

之前使用的方法如下:

  1. // Android 6.0之前的版本可以用的方法(模拟器可以使用)
  2. private String getMacAddrOld()
  3. {
  4. String macString = "";
  5. WifiManager wifimsg = (WifiManager)getSystemService(Context.WIFI_SERVICE);
  6. if (wifimsg != null)
  7. {
  8. if (wifimsg.getConnectionInfo() != null)
  9. {
  10. if (wifimsg.getConnectionInfo().getMacAddress() != null)
  11. {
  12. macString = wifimsg.getConnectionInfo().getMacAddress();
  13. }
  14. }
  15. }
  16. return macString;
  17. }

使用这个方法,在模拟器上是可以正常获取wifi mac地址,但是在Android 6.0系统上,获取的就有问题,返回的是“02:00:00:00:00:00”

谷歌搜到了如下的方法,可以获取Android6.0系统的wifi Mac 地址。

但是这个方法,却获取不到模拟器的地址,或者是获取到的和上面的方法不同,而且不准确。

  1. public static String getMacAddr() {
  2. try {
  3. List<NetworkInterface> all = Collections.list(NetworkInterface.getNetworkInterfaces());
  4. for (NetworkInterface nif : all) {
  5. if (!nif.getName().equalsIgnoreCase("wlan0")) continue;
  6.  
  7. byte[] macBytes = nif.getHardwareAddress();
  8. if (macBytes == null) {
  9. return "";
  10. }
  11.  
  12. StringBuilder res1 = new StringBuilder();
  13. for (byte b : macBytes) {
  14. res1.append(String.format("%02X:",b));
  15. }
  16.  
  17. if (res1.length() > 0) {
  18. res1.deleteCharAt(res1.length() - 1);
  19. }
  20. return res1.toString();
  21. }
  22. } catch (Exception ex) {
  23. }
  24. return "02:00:00:00:00:00";
  25. }

  最后,是先使用旧的方法获取,如果获取到的是“02:00:00:00:00:00”,那么就调用下面的新方法。

  1. public String getDeviceMacAddress()
  2. {
  3. String addr = getMacAddrOld();
  4. if(addr.equals("02:00:00:00:00:00"))
  5. {
  6. addr = getMacAddr();
  7. }
  8. return addr;
  9. }

【欢迎转载】

转载请表明出处: 乐学习

android 取mac若干问题的更多相关文章

  1. android获取Mac地址和IP地址

    获取Mac地址实际项目中测试了如下几种方法:(1)设备开通Wifi连接,获取到网卡的MAC地址(但是不开通wifi,这种方法获取不到Mac地址,这种方法也是网络上使用的最多的方法) //根据Wifi信 ...

  2. 取MAC地址 (含多网卡),最好的方法,支持Vista,Win7

    取MAC地址 (含多网卡),最好的方法,支持Vista,Win7 unit Unit1; interface usesWindows, Messages, SysUtils, Variants, Cl ...

  3. (转载) Android开发mac /dev/kvm is not found

    Android开发mac /dev/kvm is not found 标签: KVMAndroid开发KVM is not found芒果Android芒果iOS 2016-10-29 16:31 2 ...

  4. IPv6升级测试指南(Android/iOS/Mac)

    目录 我们升级到IPv6的原因 测试的时候的注意要点 Android/IOS/MAC测试总结 Android测试IPv6的方法 IOS端测试IPv6的方法 MAC浏览器端测试IPv6的方法 升级IPV ...

  5. Android开发-mac上使用三星S3做真机调试

    之前一直未使用真机进行Android开发,为准备明天的培训,拿出淘汰下来的s3准备环境,竟然发现无法连接mac,度娘一番找到答案,如下:mac 系统开发android,真机调试解决方案(无数的坑之后吐 ...

  6. 【Android】Mac安装EasyTether导致无法识别设备的问题

    正文 想让手机走PC网络,然后抓包,于是搜索一番后安装了一个叫EasyTether的软件.还没来得及测试,就忙着写代码去了,重启MAC以后就发现连不上手机了,一开始并没有怀疑是 EasyTether的 ...

  7. Journey of Android for Mac

    下了决心要学Java,几个同事都建议我去学Android,自己觉得能做点应用放手机上玩玩也比较有动力. 沈逸有篇文章里面写道: 搞C的看不起搞C++的. 搞C++的看不起搞java的. 搞java的看 ...

  8. Android studio mac版本快捷键

    Mac下快捷键的符号所对应的按键 ⌥—> option|alt ⇧—>shift ⌃—>control ⌘—>command ⎋—>esc 注: 与F6/F7/F12等F ...

  9. weex 启动 android 模拟器(mac环境)

    一.android studio和android sdk下载 1.android studio下载并安装https://developer.android.com/studio/index.html ...

随机推荐

  1. xml数据发送请求,读取xml

    # coding:utf-8 import requests url = "http://httpbin.org/post" # python3字符串换行,在右边加个反斜杠 bod ...

  2. swift笔记——环境搭建及Hello,Swift!

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/enson16855/article/details/29829601 首先要下载XCode6,仅仅有 ...

  3. boost之算法

    STL里的算法已经很好了,在boost里有几个小的算法 1.BOOST_FOREACH使用方法,定义一个容器里内部类型数据,容器作为参数传递. #include <iostream> #i ...

  4. SSH远程登陆docker容器

    环境: Ubuntu 16.04(mac osx的VMware Fushion环境) 任务: Ubuntu 16.04通过SSH登陆docker(目的是为了运行在其他服务器的Jenkins访问dock ...

  5. [笔记]Go语言在Linux环境下输出彩色字符

    Go语言要打印彩色字符与Linux终端输出彩色字符类似,以黑色背景高亮绿色字体为例: fmt.Printf("\n %c[1;40;32m%s%c[0m\n\n", 0x1B, & ...

  6. php基础知识测试总结

    1.LAMP具体结构包括Linux系统,Apache服务器,MySQL数据库,PHP语言. WAMP具体结构包括Windows系统,Apache服务器,MySQL数据库,PHP语言. 2.B/S架构: ...

  7. 请求json和xml数据时的方式

    当请求xml数据时,直接通过NSMutableData接收后解析, NSURL *url = [NSURL URLWithString:PATH]; _receiveData = [[NSMutabl ...

  8. $ 用python处理Excel文档(1)——用xlrd模块读取xls/xlsx文档

    本文主要介绍xlrd模块读取Excel文档的基本用法,并以一个GDP数据的文档为例来进行操作. 1. 准备工作: 1. 安装xlrd:pip install xlrd 2. 准备数据集:从网上找到的1 ...

  9. MySQL-版本及服务介绍

    一.MySQL各版本 1.MySQL产品 下载地址:https://www.mysql.com/downloads/ Oracle MySQL Cloud Service(commercial) 商业 ...

  10. samtools使用过程中出现的问题

    1.EOP marker is absent 在使用samtools index时出现 EOF是指the end of file,即samtools认为你的bam文件是不完整的. 如果把view参数的 ...