Android 性能优化(13)网络优化( 9)Determining and Monitoring the Docking State and Type
This lesson teaches you to
- Determine the Current Docking State
- Determine the Current Dock Type
- Monitor for Changes in the Dock State or Type
You should also read
Android devices can be docked into several different kinds of docks. These include car or home docks and digital versus analog docks. The dock-state is typically closely linked to the charging state as many docks provide power to docked devices.
How the dock-state of the phone affects your update rate depends on your app. You may choose to increase the update frequency of a sports center app when it's in the desktop dock, or disable your updates completely if the device is car docked. Conversely, you may choose to maximize your updates while car docked if your background service is updating traffic conditions.
The dock state is also broadcast as a sticky Intent
, allowing you to query if the device is docked or not, and if so, in which kind of dock.
Determine the Current Docking State
The dock-state details are included as an extra in a sticky broadcast of the ACTION_DOCK_EVENT
action. Because it's sticky, you don't need to register a BroadcastReceiver
. You can simply callregisterReceiver()
passing in null
as the broadcast receiver as shown in the next snippet.
IntentFilter ifilter = new IntentFilter(Intent.ACTION_DOCK_EVENT);
Intent dockStatus = context.registerReceiver(null, ifilter);
You can extract the current docking status from the EXTRA_DOCK_STATE
extra:
int dockState = battery.getIntExtra(EXTRA_DOCK_STATE, -);
boolean isDocked = dockState != Intent.EXTRA_DOCK_STATE_UNDOCKED;
Determine the Current Dock Type
If a device is docked, it can be docked in any one of four different type of dock:
- Car
- Desk
- Low-End (Analog) Desk
- High-End (Digital) Desk
Note that the latter two options were only introduced to Android in API level 11, so it's good practice to check for all three where you are only interested in the type of dock rather than it being digital or analog specifically:
boolean isCar = dockState == EXTRA_DOCK_STATE_CAR;
boolean isDesk = dockState == EXTRA_DOCK_STATE_DESK ||
dockState == EXTRA_DOCK_STATE_LE_DESK ||
dockState == EXTRA_DOCK_STATE_HE_DESK;
Monitor for Changes in the Dock State or Type
Whenever the device is docked or undocked, the ACTION_DOCK_EVENT
action is broadcast. To monitor changes in the device's dock-state, simply register a broadcast receiver in your application manifest as shown in the snippet below:
<action android:name="android.intent.action.ACTION_DOCK_EVENT"/>
You can extract the dock type and state within the receiver implementation using the same techniques described in the previous step.
Android 性能优化(13)网络优化( 9)Determining and Monitoring the Docking State and Type的更多相关文章
- 《Android开发艺术探索》读书笔记 (13) 第13章 综合技术、第14章 JNI和NDK编程、第15章 Android性能优化
第13章 综合技术 13.1 使用CrashHandler来获取应用的Crash信息 (1)应用发生Crash在所难免,但是如何采集crash信息以供后续开发处理这类问题呢?利用Thread类的set ...
- Android性能优化典范(二)
Google前几天刚发布了Android性能优化典范第2季的课程,一共20个短视频,包括的内容大致有:电量优化,网络优化,Wear上如何做优化,使用对象池来提高效率,LRU Cache,Bitmap的 ...
- android app性能优化大汇总(google官方Android性能优化典范 - 第2季)
Google前几天刚发布了Android性能优化典范第2季的课程,一共20个短视频,包括的内容大致有:电量优化,网络优化,Wear上如何做优化,使用对象池来提高效率,LRU Cache,Bitmap的 ...
- Android性能优化典范 - 第2季
Google发布了Android性能优化典范第2季的课程,一共20个短视频,包括的内容大致有:电量优化,网络优化,Wear上如何做优化,使用对象池来提高效率,LRU Cache,Bitmap的缩放,缓 ...
- Android 性能优化探究
使用ViewStub动态载入布局.避免一些不常常的视图长期握住引用: ViewStub的一些特点: 1. ViewStub仅仅能Inflate一次,之后ViewStub对象被置空:某个被ViewStu ...
- android 性能优化
本章介绍android高级开发中,对于性能方面的处理.主要包括电量,视图,内存三个性能方面的知识点. 1.视图性能 (1)Overdraw简介 Overdraw就是过度绘制,是指在一帧的时间内(16. ...
- Android性能优化典范第二季
Google前几天刚发布了Android性能优化典范第2季的课程,一共20个短视频,包括的内容大致有:电量优化,网络优化,Wear上如何做优化,使用对象池来提高效率,LRU Cache,Bitma ...
- Android性能优化典范第一季
2015年伊始,Google发布了关于Android性能优化典范的专题,一共16个短视频,每个3-5分钟,帮助开发者创建更快更优秀的Android App.课程专题不仅仅介绍了Android系统中有关 ...
- [转]Android性能优化典范
2015年伊始,Google发布了关于Android性能优化典范的专题,一共16个短视频,每个3-5分钟,帮助开发者创建更快更优秀的Android App.课程专题不仅仅介绍了Android系统中有关 ...
随机推荐
- 2018/3/4 Activiti教程之流程部署篇(与Springboot整合版)二
首先我们来看下Activiti为我们自动生成的这四张用户相关的表 先看下USER表 我已经插入了一些数据,很明显,就是保存用户的信息的 看下GROUP 用户对应的分组信息 MEMBERSHIP 用户和 ...
- Spring Boot - how to configure port
https://stackoverflow.com/questions/21083170/spring-boot-how-to-configure-port
- 【进击后端】ubuntu 快速安装node mongodb express
安装软件:node,mongo,express 1.apt install node 2.node -v 3.apt install mongodb 4.mongo -version 5.apt in ...
- SGU 439 A Secret Book
解法: 对于第二个串,循环移动能得到的字典序最小的串,可以直接用最小表示法搞定. 然后用最小表示的第二个串和第一个串做两次扩展KMP,一次正常求,另外一次将两个串都反转一下,然后扫一遍ex[]数组 # ...
- FTP指令说明
安装vsftpd: listen=YES: 是否监听端口 anonymous_enable=NO: 是否启用匿名用户 local_enable=YES: 是否允许本地用户登录 write_enable ...
- 神马都是浮云,unity中自己写Coroutine协程源代码
孙广东 2014.7.19 无意之间看到了,Unity维基上的一篇文章, 是关于自己写协程的介绍. 认为非常好,这样能更好的了解到协程的执行机制等特性.还是不错的. 原文链接地址例如以下: ht ...
- EXCEL单元格的获取——多例模式
因为Excel的单元格的行列与单元格是一一相应的,行与列组成的是一对联合主键.给定一个单元格行列或者给定一个单元格名称.须要找到相应的单元格:这样就形成了一种映射关系.须要使用单例模式的变式--多例模 ...
- 在对象内部尽量直接訪问实例变量 --Effictive Objective-C 抄书
在对象之外訪问实例变量时,应该总是通过属性来做.在那么在对象内部訪问实例变量的时候,又该怎样呢? 这是 OCer们一直激烈讨论的问题.有人觉得,不管什么情况,都应该通过属性来訪问实例变量;也有人说,& ...
- 在Android程序中使用已有的SQLite数据库
已经将这篇文章迁移至 Code问答,你也能够到这里查看这篇文章,请多多关注我的新技术博客CodeWenDa.com 在中文搜索中,没有找到一篇比較好的关于怎样在Android应用中使用自己事先创建好的 ...
- tesnorflow Batch Normalization
1.train或者从checkpoint restore后发现moving_mean和moving_variance都是0和1 bn1_mean = graph.get_tensor_by_name( ...