ddmlib问题总结——同步获取设备信息
通过IDevice.getProperty(String name)得到响应的设备属性。
在实际的使用过程中发现,我的manufacturer总是获取不到,为null(获取代码如下),而剩下的属性都可以获取到,经过测试,如果将manufacturer放在下面,第一个属性总是获取不到,于是到方法定义处查看注释
// 得到指定的设备属性
manufacturer = device.getProperty(IDevice.PROP_DEVICE_MANUFACTURER); // 这个属性总是无法获取,如果将它和model换一下位置,那么变成model为null
model = device.getProperty(IDevice.PROP_DEVICE_MODEL);
version = device.getProperty(IDevice.PROP_BUILD_VERSION);
apiLevel = device.getProperty(IDevice.PROP_BUILD_API_LEVEL);
观察IDevice.getProperty()的定义:
/**
* Convenience method that attempts to retrieve a property via
* {@link #getSystemProperty(String)} with minimal wait time, and swallows exceptions.
*
* @param name the name of the value to return.
* @return the value or <code>null</code> if the property value was not immediately available
*/
@Nullable
String getProperty(@NonNull String name);
注释大意:利用getSystemProperty()方法在最短的等待时间内获得一个设备属性,如果在这个瞬间该属性是不可用的,则返回null。
应该大致可以定位原因了:1.本方法为异步方法,2.默认等待时间过短
再观察一下IDevice的子类Device的重写方法:
Future<String> future = mPropFetcher.getProperty(name);return future.get(GET_PROP_TIMEOUT_MS, TimeUnit.MILLISECONDS);
其中future.get(long timeout, TimeUtil unit)方法比较特殊:
/**
* Waits if necessary for at most the given time for the computation
* to complete, and then retrieves its result, if available.
*
* @param timeout the maximum time to wait
* @param unit the time unit of the timeout argument
* @return the computed result
* @throws CancellationException if the computation was cancelled
* @throws ExecutionException if the computation threw an
* exception
* @throws InterruptedException if the current thread was interrupted
* while waiting
* @throws TimeoutException if the wait timed out
*/
V get(long timeout, TimeUnit unit)
throws InterruptedException, ExecutionException, TimeoutException;
该方法将会等待timeout长度的时间,直到你需要的属性可用未知。
根据我们上边定位出来的两个原因:
1.本方法为异步方法,2.默认等待时间过短
可以有两种解决方法:
1.改为同步获取
使用IDevice的getPropertySync(String name)方法来强制同步获取,不过在代码注释中该方法已经被放弃使用了,我没有试过这种方式。
2.增加默认等待时间
适用于可以修改代码的同学:
private static final long GET_PROP_TIMEOUT_MS = 100; // 从100改为1000
ddmlib问题总结——同步获取设备信息的更多相关文章
- Android 获取设备信息 异常
/**获取设备信息 * @param c * @return */ public static void setDeviceInfo(Context c,RequestParams params){ ...
- React Native(五)——获取设备信息react-native-device-info
心酸史: 自从接触rn开始后,越来越多的引入第三方组件而开始的配置文件,让自己一再头疼: 明明是按照官方文档一步一步的配置,为什么别人可以做到的自己却屡屡出错,真是哭笑不得--从微信分享react-n ...
- 微信小程序 --- 获取设备信息
获取设备信息: wx.getSystemInfo model:手机型号 pixelRatio:设备像素比 windowWidth:窗口宽度 windowHeight:窗口高度 language:语言 ...
- PhoneGap获取设备信息
一. 获取设备信息的方法列表(如果没有或者检测不出来就显示undefined) 1.device.name 设备名称(一些国产机检测不出来) 2.device.model ...
- appium自动化测试框架——封装获取设备信息类
在上一节中,我们已经解决了如何在python中执行cmd,并获取执行结果.下面就小小实战一下,获取设备信息. 一.思路 1.windows上获取设备信息的方法 输入dos命令“adb devices” ...
- 小白学phoneGap《构建跨平台APP:phoneGap移动应用实战》连载五(使用PhoneGap获取设备信息)
除了能够将HTML页面打包成可以直接安装运行的APP外,PhoneGap的一个最大优势在于可以通过JavaScript调用设备来访问设备上的硬件信息,从而实现一些原本只有依靠原生SDK才能够达到的目的 ...
- 微信小程序把玩(三十八)获取设备信息 API
原文:微信小程序把玩(三十八)获取设备信息 API 获取设备信息这里分为四种, 主要属性: 网络信息wx.getNetWorkType, 系统信息wx.getSystemInfo, 重力感应数据wx. ...
- 测试成长记录:python调adb无法获取设备信息bug记录
背景介绍: 一直在负责公司Android自动化的编写工作,采用的是uiautomator2,需要获取设备id来连接设备,就是 adb devices 问题描述: 之前一直用 subprocess.ch ...
- C#使用Xamarin开发可移植移动应用终章(11.获取设备信息与常用组件,开源一个可开发模版.)
前言 系列目录 C#使用Xamarin开发可移植移动应用目录 源码地址:https://github.com/l2999019/DemoApp 可以Star一下,随意 - - 说点什么.. 本系列,终 ...
随机推荐
- Cucumber java + Webdriver(一)
一.打开Eclipse,新建一个maven项目,打开pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xm ...
- Problem A: 种树 解题报告
Problem A: 种树 Description 很久很久以前,一个蒟蒻种了一棵会提问的树,树有\(n\)个节点,每个节点有一个权值,现在树给出\(m\)组询问,每次询问两个值:树上一组点对\((x ...
- ssm框架junit简单测试_我写
第一步:导入相关jar包 主要是 junit包,和spring-test包 <dependecy> <groupId>junit</groupId> <art ...
- adb logcat介绍
logcat命令语法: [adb] logcat [<option>] ... [<filter-spec>] ... adb logcat -c 清除所有以前的日志 adb ...
- 常用日期计算SQL语句
-- 本月的第一天 SELECT DATEADD(mm, DATEDIFF(mm,0,getdate()), 0) -- 本月的最后一天 SELECT DATEADD(ms,-3,DATEADD(mm ...
- Access与SQL Server 语法差异
序号 简述 Access语法 SqlServer语法 Oracle语法 解决方案 01 系统时间 Now(),Date() GETDATE() SYSDATE GetSysTimeStr 02 连接字 ...
- python的类的继承-接口继承-归一化设计
1.先在子类本身找,如果子类没有,会去父类找 class Dad: '这个是爸爸类' money=10#Dad类的数据属性 def __init__(self,name): print("爸 ...
- 一文掌握Docker Compose
目录 Docker Compose介绍 Docker Compose安装 Docker Compose基本示例 1.基本文件及目录设置 2.创建一个Dockerfile 3.通过docker-comp ...
- python---补充locals()变量在变量分发中的使用
在Django,tornado等框架中,变量分发渲染模板是一件再平常不过的事,但是当变量过多时,如何快速的进行变量传递 此时就可以用到locals()获取本地变量,将变量变为字典传入 def intr ...
- SpringBoot入门Demo(Hello Word Boot)
Spring Boot 是由Pivotal团队提供的全新框架,其设计目的是用来简化新的Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置. ...