Android中电池信息(Battery information)的取得
- 格式:doc
- 大小:60.50 KB
- 文档页数:18
很多网友询问android有没有暗码等等,除了常规的*#06#可以查看手机串号外,Android 系统还隐藏着一个工程测试模式暗码,同样在Dialer中输入*#*#4636#*#*如图所示(图中最后一位没有输入),这时可以看到出现了T esting的界面,包含了Phone information、Battery information、battery history、usage statistics四个选项,如图:
这里在Phone info中可以看到手机的IMEI、IMSI以及手机电话号码和当前使用的网络,同时和Google服务器的联网畅通,可以单击下面的Run Ping test按钮,里面可以显示远程的IP地址、还有当前手机的信号强度、LAC、CID信息、邻接小区cellid、漫游模式等等,在下面可以看到PPP 传输,在adb中可以设置ppp链接,对于开发等功能测试还是比较强大的。
而在Battery info中可以看到电池状态、温度、电压等等信息,如图
Battery history是查看电池的消耗记录。
我们可以看到程序运行、屏幕、wifi等功能所消耗的电源百分比。
此外,android工程模式中的usage statistics是查看程序的历史运行时间。
/app/bianjieshenghuo/android_94.html。
dumpsys batterystats解析在智能手机的使用过程中,电池续航是一项至关重要的指标。
Android系统为了帮助开发者了解和分析应用的电池消耗情况,提供了一系列的工具和命令。
其中,`dumpsys batterystats`命令是获取电池统计信息的有效手段。
本文将为您详细解析`dumpsys batterystats`命令的输出内容,帮助您更好地理解应用的电池使用情况。
一、`dumpsys batterystats`命令简介`dumpsys batterystats`是Android系统中一个非常有用的命令行工具,它可以提供详细的电池使用情况统计数据。
这些数据包括但不限于:各个应用的CPU使用时间、网络使用情况、GPS使用情况、屏幕亮起时间等。
要使用这个命令,您需要先开启USB调试模式,然后通过ADB连接到您的Android设备,并在命令行中输入以下命令:```adb shell dumpsys batterystats```执行这个命令后,系统将输出大量的电池统计信息。
二、`dumpsys batterystats`输出内容解析1.电池总使用时间在`dumpsys batterystats`的输出内容中,首先会显示电池的总使用时间,包括设备从上次拔下电源至今的使用时间,以及电池从满电至今的使用时间。
2.应用统计信息接下来,输出内容会列出各个应用的电池使用情况。
主要包括以下几个方面:- wakeLockTime:应用持有唤醒锁的时间。
- cpuTime:应用在CPU上运行的时间。
- runTime:应用在前台运行的时间。
- gpsTime:应用使用GPS的时间。
- wakelock:应用持有的唤醒锁数量。
- network:应用的网络使用情况,包括Mobile和WiFi。
3.其他统计信息除了应用统计信息外,`dumpsys batterystats`还会输出以下内容:- screenOnTime:屏幕亮起的时间。
要转载请注明出处:/blog/1066113,有很多转载了文章不写出处,还写的是什么小编最近做项目碰到什么问题怎么解决的的然后把文章贴下面,俨然一副他们自己的文章,不知羞耻!一、内存(ram):android的总内存大小信息存放在系统的/proc/meminfo文件里面,可以通过读取这个文件来获取这些信息:Java代码1public void getTotalMemory(){2String str1="/proc/meminfo";3String str2="";4try{5FileReader fr=new FileReader(str1);6BufferedReader localBufferedReader=new BufferedReader(fr,8192);7while((str2=localBufferedReader.readLine())!=null){8Log.i(TAG,"---"+str2);9}10}catch(IOException e){11}12}运行信息如下:Java代码1305-3008:05:14.807:INFO/-SystemInfo-(1519):---MemTotal:204876kB1405-3008:05:14.807:INFO/-SystemInfo-(1519):---MemFree: 4596kB1505-3008:05:14.807:INFO/-SystemInfo-(1519):---Buffers: 16020kB1605-3008:05:14.807:INFO/-SystemInfo-(1519):---Cached: 82508kB1705-3008:05:14.807:INFO/-SystemInfo-(1519):---SwapCached:64kB1805-3008:05:14.807:INFO/-SystemInfo-(1519):---Active: 137104kB1905-3008:05:14.807:INFO/-SystemInfo-(1519):---Inactive:41056kB2005-3008:05:14.807:INFO/-SystemInfo-(1519):---SwapTotal:65528kB2105-3008:05:14.817:INFO/-SystemInfo-(1519):---SwapFree:65368kB2205-3008:05:14.817:INFO/-SystemInfo-(1519):---Dirty: 88kB2305-3008:05:14.817:INFO/-SystemInfo-(1519):---Writeback:0kB2405-3008:05:14.817:INFO/-SystemInfo-(1519):---AnonPages:79672kB2505-3008:05:14.817:INFO/-SystemInfo-(1519):---Mapped: 38296kB2605-3008:05:14.817:INFO/-SystemInfo-(1519):---Slab: 5768kB2705-3008:05:14.817:INFO/-SystemInfo-(1519):---SReclaimable:1856kB2805-3008:05:14.827:INFO/-SystemInfo-(1519):---SUnreclaim:3912kB2905-3008:05:14.827:INFO/-SystemInfo-(1519):---PageTables:8184kB3005-3008:05:14.827:INFO/-SystemInfo-(1519):---NFS_Unstable:0kB3105-3008:05:14.827:INFO/-SystemInfo-(1519):---Bounce: 0kB3205-3008:05:14.827:INFO/-SystemInfo-(1519):---CommitLimit:167964kB3305-3008:05:14.827:INFO/-SystemInfo-(1519):---Committed_AS:11771920kB3405-3008:05:14.827:INFO/-SystemInfo-(1519):---VmallocTotal:761856kB3505-3008:05:14.827:INFO/-SystemInfo-(1519):---VmallocUsed:83656kB3605-3008:05:14.827:INFO/-SystemInfo-(1519):---VmallocChunk:674820kB第一行是总内存大小(即用户可以使用的ram的大小)!其他各项的介绍大家可以看这儿:/android-phones-to-get-the-total-memory-and -available-memory.html获取当前剩余内存(ram)大小的方法:Java代码37public long getAvailMemory(){38ActivityManager am=(ActivityManager)mContext.getSystemService(Context.ACTIV ITY_SERVICE);39ActivityManager.MemoryInfo mi=newActivityManager.MemoryInfo();40am.getMemoryInfo(mi);41return mi.availMem;42}二、Rom大小Java代码43public long[]getRomMemroy(){44long[]romInfo=new long[2];45//Total rom memory46romInfo[0]=getTotalInternalMemorySize();4748//Available rom memory49File path=Environment.getDataDirectory();50StatFs stat=new StatFs(path.getPath());51long blockSize=stat.getBlockSize();52long availableBlocks=stat.getAvailableBlocks();53romInfo[1]=blockSize*availableBlocks;54getVersion();55return romInfo;56}5758public long getTotalInternalMemorySize(){59File path=Environment.getDataDirectory();60StatFs stat=new StatFs(path.getPath());61long blockSize=stat.getBlockSize();62long totalBlocks=stat.getBlockCount();63return totalBlocks*blockSize;64}注意类型,不然相乘之后会有溢出。
android电池节点
Android系统中的电池节点指的是在系统文件中用于管理和监控电池相关信息的节点。
这些节点通常位于
/sys/class/power_supply目录下,不同的Android设备可能会有些许差异。
在这些节点中,用户和开发者可以获取关于电池状态、电量、温度、电压等各种电池相关信息。
通过读取这些节点,用户可以了解设备当前的电池使用情况,比如剩余电量、充电状态、充电方式等。
开发者也可以利用这些节点来编写应用程序或者小工具,实现电池状态的监控、优化电池使用等功能。
在Android系统中,访问这些电池节点通常需要root权限或者系统权限,因为这些节点涉及到系统底层的操作和信息。
因此,普通用户在未经授权的情况下是无法直接访问和修改这些节点的。
总的来说,Android系统中的电池节点是用于管理和监控电池相关信息的系统文件节点,通过读取这些节点可以获取电池的各种状态和参数,对于用户和开发者来说都具有一定的重要性。
在android开发中,可通过如下方式获取手机电量:Java代码1.import android.app.Activity;2.import android.app.Dialog;3.import android.content.BroadcastReceiver;4.import android.content.Context;5.import android.content.Intent;6.import android.content.IntentFilter;7.import android.os.Bundle;8.import android.util.Log;9.import android.view.View;10.import android.view.Window;11.import android.view.WindowManager;12.import android.widget.Button;13.import android.widget.TextView;14.15.public class BatteryInfo extends Activity16.{17. /* 变量声明 */18. private int intLevel;19. private int intScale;20. private Button mButton01;21.22. /* 创建BroadcastReceiver */23. private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver()24. {25. public void onReceive(Context context, Intent intent)26. {27. String action = intent.getAction();28. /*29. * 如果捕捉到的action是ACTION_BATTERY_CHANGED,就运行onBatteryInfoReceiver()30. */31. if (Intent.ACTION_BATTERY_CHANGED.equals(action))32. {33. intLevel = intent.getIntExtra("level", 0);34. intScale = intent.getIntExtra("scale", 100);35. Log.i("", "intLevel = " + intLevel);36. Log.i("", "intScale = " + intScale);37. onBatteryInfoReceiver(intLevel, intScale);38. }39. }40. };41.42. /** Called when the activity is first created. */43. @Override44. public void onCreate(Bundle savedInstanceState)45. {46. super.onCreate(savedInstanceState);47. setContentView(yout.main);48.49. mButton01 = (Button) findViewById(R.id.myButton1);50. mButton01.setOnClickListener(new Button.OnClickListener()51. {52. public void onClick(View v)53. {54.55. // 注册一个系统 BroadcastReceiver,作为访问电池计量之用56. // 這個不能直接在AndroidManifest.xml中註冊57. registerReceiver(mBatInfoReceiver, new IntentFilter(58. Intent.ACTION_BATTERY_CHANGED));59. }60. });61. }62.63. /* 捕捉到ACTION_BATTERY_CHANGED时要运行的method */64. public void onBatteryInfoReceiver(int intLevel, int intScale)65. {66. /* create 跳出的对话窗口 */67. final Dialog d = new Dialog(BatteryInfo.this);68. d.setTitle(R.string.str_dialog_title);69. d.setContentView(yout.mydialog);70.71. /* 创建一个背景模糊的Window,且将对话窗口放在前景 */72. Window window = d.getWindow();73. window.setFlags(youtParams.FLAG_BLUR_BEHIND,74. youtParams.FLAG_BLUR_BEHIND);75.76. /* 将取得的电池计量显示于Dialog中 */77. TextView mTextView02 = (TextView) d.findViewById(R.id.myTextView2);78. mTextView02.setText(getResources()79. .getText(R.string.str_dialog_body)80. + String.valueOf(intLevel * 100 / intScale) + "%");81.82. /* 设置返回主画面的按钮 */83. Button mButton02 = (Button) d.findViewById(R.id.myButton2);84. mButton02.setOnClickListener(new Button.OnClickListener()85. {86. public void onClick(View v)87. {88. /* 反注册Receiver,并关闭对话窗口 */89. unregisterReceiver(mBatInfoReceiver);90. d.dismiss();91. }92. });93. d.show();94. }95.}96.复制代码代码里还用到了自定义的Dialog布局:Java代码1.<?xml version="1.0" encoding="utf-8"?>2.<LinearLayout xmlns:android="/apk/res/android"3. android:background="@drawable/white" android:orientation="vertical"4. android:layout_width="fill_parent" android:layout_height="fill_parent">5. <TextView android:id="@+id/myTextView2"android:layout_width="fill_parent"6. android:layout_height="wrap_content"android:textColor="@drawable/blue"7. android:textSize="16sp" android:gravity="center"android:padding="10px">8. </TextView>9. <Button android:id="@+id/myButton2"android:layout_width="wrap_content"10. android:layout_height="wrap_content"android:text="@string/str_button2">11. </Button>12.</LinearLayout>13.复制代码如需了解更多相关知识,请至麦子学院官网查询(/)。
安卓系统权限中英文对照网上搜集的安卓系统软件的权限中英文对照程序执行需要读取到安全敏感项必需在androidmanifest.xml中声明相关权限请求, 完整列表如下:android.permission.ACCESS_CHECKIN_PROPERTIES允许读写访问”properties”表在checkin数据库中,改值可以修改上传( Allows read/write access to the “properties” table in the checkin database, to change value s that get uploaded) android.permission.ACCESS_COARSE_LOCA TION允许一个程序访问CellID或WiFi热点来获取粗略的位置(Allows an application to access coarse (e.g., Cell-ID, WiFi) location) copyright dedecmsandroid.permission.ACCESS_FINE_LOCA TION允许一个程序访问精良位置(如GPS) (Allows an application to access fine (e.g., GPS) location) android.permission.ACCESS_LOCA TION_EXTRA_COMMANDS 允许应用程序访问额外的位置提供命令(Allows an application to access extra location provider commands)android.permission.ACCESS_MOCK_LOCA TION允许程序创建模拟位置提供用于测试(Allows an application to create mock location providers for testing)android.permission.ACCESS_NETWORK_STA TE允许程序访问有关GSM网络信息(Allows applications to access information about networks) android.permission.ACCESS_SURFACE_FLINGER允许程序使用SurfaceFlinger底层特性(Allows an application to use SurfaceFlinger’s low level features)android.permission.ACCESS_WIFI_STA TE允许程序访问Wi-Fi网络状态信息(Allows applications to accessinformation about Wi-Fi networks)android.permission.ADD_SYSTEM_SERVICE允许程序发布系统级服务(Allows an application to publish system-level services).android.permission.BA TTERY_STA TS允许程序更新手机电池统计信息(Allows an application to update the collected battery statistics) android.permission.BLUETOOTH允许程序连接到已配对的蓝牙设备(Allows applications to connect to paired bluetooth devices) android.permission.BLUETOOTH_ADMIN允许程序发现和配对蓝牙设备(Allows applications to discover and pair bluetooth devices) android.permission.BRICK 请求能够禁用设备(非常危险)(Required to be able to disable the device (very *erous!).) android.permission.BROADCAST_PACKAGE_REMOVED 允许程序广播一个提示消息在一个应用程序包已经移除后(Allows an application to broadcast a notification that an application package has been removed)android.permission.BROADCAST_STICKY允许一个程序广播常用intents(Allows an application to broadcast sticky intents) /doc/926213707.html,android.permission.CALL_PHONE允许一个程序初始化一个电话拨号不需通过拨号用户界面需要用户确认(Allows an application to initiate a phone call without going through the Dialer user interface for the user to confirm the call being placed.)android.permission.CALL_PRIVILEGED允许一个程序拨打任何号码,包含紧急号码无需通过拨号用户界面需要用户确认(Allows an application to call any phone number, including emergency numbers, without going through the Dialer user interface for the user to confirm the call being placed) android.permission.CAMERA请求访问使用照相设备(Required to be able to access the camera device. )android.permission.CHANGE_COMPONENT_ENABLED_STA TE允许一个程序是否改变一个组件或其他的启用或禁用(Allows an application to change whether an application component (other than its own) is enabled or not. )android.permission.CHANGE_CONFIGURA TION允许一个程序修改当前设置,如本地化(Allows an application to modify the current configuration, such as locale. )android.permission.CHANGE_NETWORK_STA TE允许程序改变网络连接状态(Allows applications to change network connectivity state) android.permission.CHANGE_WIFI_STA TE允许程序改变Wi-Fi连接状态(Allows applications to change Wi-Fi connectivity state) android.permission.CLEAR_APP_CACHE 允许一个程序清楚缓存从所有安装的程序在设备中(Allows an application to clear the caches of all installed applications on the device. )android.permission.CLEAR_APP_USER_DA TA允许一个程序清除用户设置(Allows an application to clear user data)android.permission.CONTROL_LOCA TION_UPDA TES允许启用禁止位置更新提示从无线模块(Allows enabling/disabling location update notifications from the radio. ) copyright dedecmsandroid.permission.DELETE_CACHE_FILES允许程序删除缓存文件(Allows an application to delete cache files)android.permission.DELETE_PACKAGES允许一个程序删除包(Allows an application to delete packages) android.permission.DEVICE_POWER允许访问底层电源管理(Allows low-level access to power management)android.permission.DIAGNOSTIC允许程序RW诊断资源(Allows applications to RW to diagnostic resources. )android.permission.DISABLE_KEYGUARD允许程序禁用键盘锁(Allows applications to disable the keyguard ) /doc/926213707.html, android.permission.DUMP允许程序返回状态抓取信息从系统服务(Allows an application to retrieve state dump information from system services.) android.permission.EXPAND_STA TUS_BAR允许一个程序扩展收缩在状态栏,android开发网提示应该是一个类似windows mobile中的托盘程序(Allows an application to expand or collapse the status bar. )android.permission.FACTORY_TEST作为一个工厂测试程序,运行在root用户(Run as a manufacturer test application, running as the root user. ) android.permission.FLASHLIGHT访问闪光灯,android开发网提示htc Dream不包含闪光灯(Allows access to the flashlight ) android.permission.FORCE_BACK 允许程序强行一个后退操作是否在顶层activities(Allows an application to force a BACK operation on whatever is the top activity. )android.permission.FOTA_UPDA TE暂时不了解这是做什么使用的,android开发网分析可能是一个预留权限.android.permission.GET_ACCOUNTS访问一个帐户列表在Accounts Service中(Allows access to the list of accounts in the Accounts Service)android.permission.GET_PACKAGE_SIZE允许一个程序获取任何package占用空间容量(Allows an application to find out the space used by any package. ) android.permission.GET_TASKS允许一个程序获取信息有关当前或最近运行的任务,一个缩略的任务状态,是否活动等等(Allows an application to get information about the currently or recently running tasks: a thumbnail representation of the tasks, what activities are running in it, etc.) android.permission.HARDWARE_TEST允许访问硬件(Allows access to hardware peripherals. )android.permission.INJECT_EVENTS允许一个程序截获用户事件如按键、触摸、轨迹球等等到一个时间流,android 开发网提醒算是hook技术吧(Allows an application to inject user events (keys, touch, trackball) into the event stream and deliver them to ANY window.)android.permission.INSTALL_PACKAGES允许一个程序安装packages(Allows an application to install packages. )android.permission.INTERNAL_SYSTEM_WINDOW允许打开窗口使用系统用户界面(Allows an application to open windows that are for use by parts of the system user interface. ) android.permission.INTERNET允许程序打开网络套接字(Allows applications to open network sockets)android.permission.MANAGE_APP_TOKENS允许程序管理(创建、催后、z- order默认向z轴推移)程序引用在窗口管理器中(Allows an application to manage (create, destroy, Z-order) application tokens in the window manager. ) android.permission.MASTER_CLEAR目前还没有明确的解释,android开发网分析可能是清除一切数据,类似硬格机android.permission.MODIFY_AUDIO_SETTINGS允许程序修改全局音频设置(Allows an application to modify global audio settings)android.permission.MODIFY_PHONE_STA TE允许修改话机状态,如电源,人机接口等(Allows modification of the telephony state – power on, mmi, etc. )android.permission.MOUNT_UNMOUNT_FILESYSTEMS允许挂载和反挂载文件系统可移动存储(Allows mounting and unmounting file systems for removable storage. )android.permission.PERSISTENT_ACTIVITY允许一个程序设置他的activities显示(Allow an application to make its activities persistent. )android.permission.PROCESS_OUTGOING_CALLS允许程序监视、修改有关播出电话(Allows an application to monitor, modify, or abort outgoing calls) 内容来自dedecms android.permission.READ_CALENDAR允许程序读取用户日历数据(Allows an application to read the user’s calendar data.)android.permission.READ_CONTACTS允许程序读取用户联系人数据(Allows an application to read the user’s contacts data.)android.permission.READ_FRAME_BUFFER允许程序屏幕波或和更多常规的访问帧缓冲数据(Allows an application to take screen shots and more generally get accessto the frame buffer data)android.permission.READ_INPUT_STA TE允许程序返回当前按键状态(Allows an application to retrieve the current state of keys and switches. )android.permission.READ_LOGS允许程序读取底层系统日志文件(Allows an application to read the low-level system log files. ) android.permission.READ_OWNER_DA TA允许程序读取所有者数据(Allows an application to read the owner’s data) /doc/926213707.html, android.permission.READ_SMS允许程序读取短信息(Allows an application to read SMS messages.)android.permission.READ_SYNC_SETTINGS允许程序读取同步设置(Allows applications to read the sync settings)android.permission.READ_SYNC_STA TS允许程序读取同步状态(Allows applications to read the sync stats)android.permission.REBOOT请求能够重新启动设备(Required to be able to reboot the device. )android.permission.RECEIVE_BOOT_COMPLETED允许一个程序接收到ACTION_BOOT_COMPLETED广播在系统完成启动(Allows an application to receive the ACTION_BOOT_COMPLETED that is broadcast after the system finishes booting. )android.permission.RECEIVE_MMS允许一个程序监控将收到MMS彩信,记录或处理(Allows an application to monitor incoming MMS messages, to record orperform processing on them. )android.permission.RECEIVE_SMS允许程序监控一个将收到短信息,记录或处理(Allows an application to monitor incoming SMS messages, to record or perform processing on them.)android.permission.RECEIVE_WAP_PUSH允许程序监控将收到W AP PUSH信息(Allows an application to monitor incoming WAP push messages. )android.permission.RECORD_AUDIO允许程序录制音频(Allows an application to record audio)android.permission.REORDER_TASKS允许程序改变Z轴排列任务(Allows an application to change the Z-order of tasks)android.permission.RESTART_PACKAGES允许程序重新启动其他程序(Allows an application to restart other applications)android.permission.SEND_SMS允许程序发送SMS短信(Allows an application to send SMS messages)android.permission.SET_ACTIVITY_WA TCHER允许程序监控或控制activities已经启动全局系统中Allows an application to watch and control how activities are started globally in the system. 内容来自dedecmsandroid.permission.SET_ALWAYS_FINISH允许程序控制是否活动间接完成在处于后台时Allows an application to control whether activities are immediately finished when put in the background.android.permission.SET_ANIMA TION_SCALE修改全局信息比例(Modify the global animation scaling factor.) android.permission.SET_DEBUG_APP配置一个程序用于调试(Configure an application for debugging.)android.permission.SET_ORIENTA TION允许底层访问设置屏幕方向和实际旋转(Allows low-level access to setting the orientation (actually rotation) of the screen.) android.permission.SET_PREFERRED_APPLICA TIONS允许一个程序修改列表参数PackageManager.addPackageT oPreferred() 和PackageManager.removePackageFromPreferred()方法(Allows an application to modify the list of preferred applications with the PackageManager.addPackageT oPreferred() and PackageManager.removePackageFromPreferred() methods.) android.permission.SET_PROCESS_FOREGROUND允许程序当前运行程序强行到前台(Allows an application to force any currently running process to be in the foreground.) android.permission.SET_PROCESS_LIMIT允许设置最大的运行进程数量(Allows an application to set the maximum number of (not needed) application processes that can be running. ) copyright dedecmsandroid.permission.SET_TIME_ZONE允许程序设置时间区域(Allows applications to set the system time zone)android.permission.SET_WALLPAPER允许程序设置壁纸(Allows applications to set the wallpaper ) android.permission.SET_WALLPAPER_HINTS允许程序设置壁纸hits(Allows applications to set the wallpaper hints)android.permission.SIGNAL_PERSISTENT_PROCESSES允许程序请求发送信号到所有显示的进程中(Allow an application to request that a signal be sent to all persistentprocesses)android.permission.STA TUS_BAR允许程序打开、关闭或禁用状态栏及图标Allows an application to open, close, or disable the status bar and its icons.android.permission.SUBSCRIBED_FEEDS_READ允许一个程序访问订阅RSS Feed内容提供(Allows an application to allow access the subscribed feeds ContentProvider. )android.permission.SUBSCRIBED_FEEDS_WRITE系统暂时保留改设置,android开发网认为未来版本会加入该功能。
[Android]深⼊浅出AndroidApp耗电量统计前⾔在Android统计App耗电量⽐较⿇烦,直⾄Android 4.4,它仍没公开“电量统计”API或⽂档……额,是的,仅没有公开,并不是没有。
平时在⼿机“设置- 电量”看到的数据就是系统调⽤内部API的统计结果。
基础概念1. ⼿机由众多“部件”组成,所谓“部件”是指:CPU,WIFI,GPS....所以,Android App消耗总电量为 App运⾏过程中,涉及各部件的消耗电量的总和。
2. 假设运⾏App导致CPU运⾏,时间:t,CPU单位时间消耗电量:w,则App的CPU耗电量为:W = w*t,⽽有物理公式 W = U*I*t(U:电压值,I:电流值),在⼿机中,⼀般U恒定不变,所以,可以单独通过 Q(电容量,单位: mAh)= I * t 表⽰电量。
系统源码分析核⼼源码:核⼼类:- BatteryStatsImpl:提供App各部件运⾏时间。
- PowerProfile:提供部件电流数值。
问题:- Android怎样存储与读取App耗电量信息(即:BatteryStatsImpl数据怎么来的?)- Android怎么存储部件电流数值(即:PowerProfile数据怎么来的?)- Android具体耗电量计算⽅法1. Android怎样存储与读取App耗电量信息(1)先看下PowerUsageSummary.java如何获取BatteryStatsImpl?可见 BatteryStatsImpl 通过系统服务“batteryinfo”获得。
(2)系统服务“batteryinfo”是什么玩意呢?(见:)系统服务“batteryinfo”其实就是BatteryStatsService,⽽BatteryStatsService“唯⼀的”构造函数提供了⼀个很重要的信息:filename!(3)BatteryStatsService在哪⾥创建?filename是什么?(见:)filename⽂件是:/data/system/batterystats.bin,关于batterystats.bin,之前民间很多⽂章说它⽤作电池校正,但Android⼯程师Dianne Hackborn在google+上明确:betterystats.bin⽂件仅仅是⼀个记录不同app使⽤电量的⼀个⽂件。
如果我们注册了对Intent.ACTION_BATTERY_CHANGED的监听,那么我们马上会收到一个Action为Intent.ACTION_BATTERY_CHANGED的intent,之后只要我们没有取消监听,电池发送变化,我们会收到这样的intent.通过该intent的extra我们可以取得电池的很多信息,比如电压/ 当前电池的健康状况等等。
比如电压可以用如下的方式:[java]view plain copyint voltage = intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE, -1);(1)EXTRA_HEALTH:当前电池的健康状态可能的取值:BATTERY_HEALTH_COLDBATTERY_HEALTH_DEADBATTERY_HEALTH_GOODBATTERY_HEALTH_OVERHEATBATTERY_HEALTH_OVER_VOLTAGEBATTERY_HEALTH_UNKNOWNBATTERY_HEALTH_UNSPECIFIED_FAILURE(2)EXTRA_ICON_SMALL:当前用于表示电池状态的icon的资源id(3)EXTRA_LEVEL: 电池当前的电量(4) EXTRA_PLUGGED: 当前手机使用的是哪里的电源可能的取值:BATTERY_PLUGGED_ACBATTERY_PLUGGED_USB(5) EXTRA_PRESENT:表示是否提供电池。
有些手机在使用USB电源的情况下,即使拔出了电池,仍然可以正常工作(6) EXTRA_SCALE:表示电池电量的最大值(7) EXTRA_STATUS:表示电池的当前状态可能的取值:BATTERY_STATUS_CHARGINGBATTERY_STATUS_DISCHARGINGBATTERY_STATUS_FULLBATTERY_STATUS_NOT_CHARGINGBATTERY_STATUS_UNKNOWN(8) EXTRA_TECHNOLOGY:表示电池使用的技术。
Android(安卓系统)系统手机使用技巧快速查看手机充电情况方法1:通过待机屏幕查看,众所周知Android系统设计了自动锁屏功能,当手机处于一段时间不使用的情况下就会自动熄灭背景灯,如果需要激活的话就需要按下手机的Menu键两次,但是当按下第一次之后会显示出待机界面,里面就会显示目前的手机电池充电情况。
方法2:在Android系统中的About Phone选项中的“Status”选项,里面能够看到Battery Level的选项,这就是当前手机的充电情况显示。
方法3:通过第三方软件查看,由于Android系统中并没有专门的这类软件,所以如果想要详细的查看目前手机充电情况的话就是用一款第三方的电池查看软件吧教你设置输入密码不可见用过某些需要登录的应用程序的朋友相信都知道在输入账户密码默认情况下是显示出来已经输入的密码,为了安全起见都不想旁边的人看到自己的密码,那么怎样才能设置Android手机不可见已经输入的密码呢?教你设置输入密码不显示。
关于密码的设置当然是在SecurityLocation中了,所以我们先在主屏界面上按下Menu菜单键,在弹出的进阶菜单中选择最后一项“Settings”;进入设置菜单后将滚动条向下滑动,找到“SecurityLocation”的分类,点击进入;在安全性和位置分类菜单中找到Passwords分类,其中将“Visible passwords”选项后面的勾去掉即可。
摩托罗拉BLUR账户设置二代账户设置步骤,有兴趣的朋友可以看看。
首次BLUR账户设置是在ME600等手机首次启动的时候,只要将MOTOBLUR账户绑定一个邮箱即可,当然在此之前需要进行APN网络接入点的设置。
如果在Android手机首次开机的时候将MOTOBLUR账户设置过程跳过,那么只能从其他地方进行设置。
在主屏幕中按下Menu菜单键,选择最后一项设置,在设置选项中选择MOTOBLUR账户进入下一步设置。
Android中电池信息(Battery information)的取得[日期:2010-08-23] 来源:Linux社区作者:Linux这里介绍电池信息的取得.Android.content.BroadcastReceiver类Android.os.BatteryManager类● 电池信息的取得,调用registerReceiver()方法。
第1个参数,设置BroadcastReceiver实例第2个参数,设置追加了Intent.ACTION_BATTERY_CHANGED处理的IntentFilter 实例。
● 在BroadcastReceiver的onReceive()事件,接收到的Intent.ACTION_BATTERY_CHANGED,包括下面的信息。
“status”(int类型)…状态,定义值是BatteryManager.BATTERY_STATUS_XXX。
“health”(int类型)…健康,定义值是BatteryManager.BATTERY_HEALTH_XXX。
“present”(boolean类型)“level”(int类型)…电池剩余容量“scale”(int类型)…电池最大值。
通常为100。
“icon-small”(int类型)…图标ID。
“plugged”(int类型)…连接的电源插座,定义值是BatteryManager.BATTERY_PLUGGED_XXX。
“voltage”(int类型) (V)“temperature”(int类型)…温度,0.1度单位。
例如表示197的时候,意思为19.7度。
“technology”(String类型)…电池类型,例如,Li-ion等等。
例程源码(Java)package com.adakoda.batterytest;import Android.app.Activity;import Android.content.BroadcastReceiver;import Android.content.Context;import Android.content.Intent;import Android.content.IntentFilter;import Android.os.BatteryManager;import Android.os.Bundle;import Android.util.Log;public class BatteryTestActivity extends Activity {/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(yout.main);}@Overrideprotected void onResume() {super.onResume();IntentFilter filter = new IntentFilter();filter.addAction(Intent.ACTION_BATTERY_CHANGED);registerReceiver(mBroadcastReceiver, filter);}@Overrideprotected void onPause() {super.onPause();unregisterReceiver(mBroadcastReceiver);}private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { @Overridepublic void onReceive(Context context, Intent intent) {String action = intent.getAction();if (action.equals(Intent.ACTION_BATTERY_CHANGED)) {int status = intent.getIntExtra("status", 0);int health = intent.getIntExtra("health", 0);boolean present = intent.getBooleanExtra("present", false); int level = intent.getIntExtra("level", 0);int scale = intent.getIntExtra("scale", 0);int icon_small = intent.getIntExtra("icon-small", 0);int plugged = intent.getIntExtra("plugged", 0);int voltage = intent.getIntExtra("voltage", 0);int temperature = intent.getIntExtra("temperature", 0);String technology = intent.getStringExtra("technology");String statusString = "";switch (status) {case BatteryManager.BATTERY_STATUS_UNKNOWN:statusString = "unknown";break;case BatteryManager.BATTERY_STATUS_CHARGING:statusString = "charging";break;case BatteryManager.BATTERY_STATUS_DISCHARGING:statusString = "discharging";break;case BatteryManager.BATTERY_STATUS_NOT_CHARGING:statusString = "not charging";break;case BatteryManager.BATTERY_STATUS_FULL:statusString = "full";break;}String healthString = "";switch (health) {case BatteryManager.BATTERY_HEALTH_UNKNOWN:healthString = "unknown";break;case BatteryManager.BATTERY_HEALTH_GOOD:healthString = "good";break;case BatteryManager.BATTERY_HEALTH_OVERHEAT:healthString = "overheat";break;case BatteryManager.BATTERY_HEALTH_DEAD:healthString = "dead";break;case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:healthString = "voltage";break;case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:healthString = "unspecified failure";break;}String acString = "";switch (plugged) {case BatteryManager.BATTERY_PLUGGED_AC:acString = "plugged ac";break;case BatteryManager.BATTERY_PLUGGED_USB:acString = "plugged usb";break;}Log.v("status", statusString);Log.v("health", healthString);Log.v("present", String.valueOf(present));Log.v("level", String.valueOf(level));Log.v("scale", String.valueOf(scale));Log.v("icon_small", String.valueOf(icon_small));Log.v("plugged", acString);Log.v("voltage", String.valueOf(voltage));Log.v("temperature", String.valueOf(temperature));Log.v("technology", technology);}}};Android中电池信息(Battery information)的取得收藏原文地址:/sharp2wing/archive/2010/08/20/5826493.aspx 这里介绍电池信息的取得.android.content.BroadcastReceiver类android.os.BatteryManager类● 电池信息的取得,调用registerReceiver()方法。
第1个参数,设置BroadcastReceiver实例第2个参数,设置追加了Intent.ACTION_BATTERY_CHANGED处理的IntentFilter 实例。
● 在BroadcastReceiver的onReceive()事件,接收到的Intent.ACTION_BATTERY_CHANGED,包括下面的信息。