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系统中有关 ...
随机推荐
- Linux下汇编语言学习笔记55 ---
这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...
- codeforces 691E(矩阵乘法)
E. Xor-sequences time limit per test 3 seconds memory limit per test 256 megabytes input standard in ...
- CSS实现自适应不同大小屏幕的背景大图的两种方法(转自简书)
CSS实现自适应不同大小屏幕的背景大图的两种方法 一张清晰漂亮的背景图片能给网页加分不少,设计师也经常会给页面的背景使用大图,我们既不想图片因为不同分辨率图片变形,也不希望当在大屏的情况下,背景有一块 ...
- Maximum Product Subarray(最大连续乘积子序列)
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- JVM(一):源文件的转变
JVM(一):源文件的转变 本文讲述一个.java源文件是如何经过javac编译器的一系列操作变为.class文件的. 编译 说到编译,大家都能想到是编译器经过一系列方法将源代码转变为目标机器代码,但 ...
- wget下载网络图片
wget http....... --no-check-certificate
- 1、Java并发性和多线程-并发性和多线程介绍
以下内容转自http://ifeve.com/java-concurrency-thread/: 在过去单CPU时代,单任务在一个时间点只能执行单一程序.之后发展到多任务阶段,计算机能在同一时间点并行 ...
- 如何使用TFTP客户端工具修复路由器固件
如何使用TFTP客户端工具修复路由器固件 编号:12083 来自:NetGear 更新日期:2013-10-14 访问数量:24650 NETGEAR无线路由器中, ...
- 【转】配置windows路由表,使电脑同时连接内网外网方法
1. 公司内部,内网和外网的网关不一样,怎么样让电脑可以同时上内网和外网呢? 来一张不相关的磁盘结构图: ----------------------------------------------- ...
- Creating A Simple Web Server With Golang
原文:https://tutorialedge.net/post/golang/creating-simple-web-server-with-golang/ -------------------- ...