问题一: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

buildTypes
{
...
sourceSets
{
main
{
jni.srcDirs = []
}
}
}

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(),如果未使用会造成内存泄露。
原:

WifiManager wifiMgr = (WifiManager) getSystemService(WIFI_SERVICE);

改:

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

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

android {
...
lintOptions{
checkReleaseBuilds false
abortOnError false
}
}

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解决办法

解决办法:

之前使用的方法如下:

// Android 6.0之前的版本可以用的方法(模拟器可以使用)
private String getMacAddrOld()
{
String macString = "";
WifiManager wifimsg = (WifiManager)getSystemService(Context.WIFI_SERVICE);
if (wifimsg != null)
{
if (wifimsg.getConnectionInfo() != null)
{
if (wifimsg.getConnectionInfo().getMacAddress() != null)
{
macString = wifimsg.getConnectionInfo().getMacAddress();
}
}
}
return macString;
}

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

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

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

public static String getMacAddr() {
try {
List<NetworkInterface> all = Collections.list(NetworkInterface.getNetworkInterfaces());
for (NetworkInterface nif : all) {
if (!nif.getName().equalsIgnoreCase("wlan0")) continue; byte[] macBytes = nif.getHardwareAddress();
if (macBytes == null) {
return "";
} StringBuilder res1 = new StringBuilder();
for (byte b : macBytes) {
res1.append(String.format("%02X:",b));
} if (res1.length() > 0) {
res1.deleteCharAt(res1.length() - 1);
}
return res1.toString();
}
} catch (Exception ex) {
}
return "02:00:00:00:00:00";
}

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

public String getDeviceMacAddress()
{
String addr = getMacAddrOld();
if(addr.equals("02:00:00:00:00:00"))
{
addr = getMacAddr();
}
return addr;
}

【欢迎转载】

转载请表明出处: 乐学习

最新文章

  1. 要将 ASP.NET 访问权限授予某个文件,请在资源管理器中右击该文件,选择“属性”,然后选择“安全”选项卡。单击“添加”添加适当的用户或组。突出显示 ASP.NET 帐户,选中所需访问权限对应的框。
  2. VBA续嘘嘘
  3. 调研一类软件的发展演变—聊天软件( 1000-2000 words, in Chinese)
  4. CentOS6.4-RMAN定时任务备份 on 11GR2
  5. POJ 1269 Intersecting Lines(直线相交判断,求交点)
  6. WPF 概述
  7. Linux curl命令参数详解--转载
  8. C++ Reference 的“三位一体”诠释
  9. RadGrid SelectedIndexChanged 事件没反应的解决方法
  10. web文档类型DOCTYPE html很重要
  11. Asp.NetCore之组件写法
  12. CountDownLatch, CyclicBarrier and Semaphore
  13. 清除 x-code 缓存
  14. EF|CodeFirst数据并发管理
  15. uiautomatorviewer 查看元素报错: Error taking device screenshot: null 原因
  16. Django Windows环境下部署
  17. Ajax概述和判断用户名是否存在的简单代码练习
  18. SQL 分隔字符串
  19. 集合(4)—Collection之Set的使用方法
  20. html5打开摄像头并用canvas模拟拍照 - 转

热门文章

  1. struts2+Oracle实现管理员查看用户提交的意见功能
  2. Python基础-文件的基本操作
  3. GCE 创建一个Linux VM
  4. NodeJS应用程序设置为window service-辅助工具(C#)
  5. 【转】通过fio工具,测试SATA,SAS,SSD 读写性能
  6. css系列(4)简介
  7. 一个可以查询CSS属性兼容性的网站。
  8. 正则表达式----grep
  9. Windos Server 2008 FTP 服务安装
  10. ACM训练小结-2018年6月16日