- 浏览: 5845847 次
- 性别:
- 来自: 上海
-
文章分类
- 全部博客 (890)
- WindowsPhone (0)
- android (88)
- android快速迭代 (17)
- android基础 (34)
- android进阶 (172)
- android高级 (0)
- android拾遗 (85)
- android动画&效果 (68)
- Material Design (13)
- LUA (5)
- j2me (32)
- jQuery (39)
- spring (26)
- hibernate (20)
- struts (26)
- tomcat (9)
- javascript+css+html (62)
- jsp+servlet+javabean (14)
- java (37)
- velocity+FCKeditor (13)
- linux+批处理 (9)
- mysql (19)
- MyEclipse (9)
- ajax (7)
- wap (8)
- j2ee+apache (24)
- 其他 (13)
- phonegap (35)
最新评论
-
Memories_NC:
本地lua脚本终于执行成功了,虽然不是通过redis
java中调用lua脚本语言1 -
ZHOU452840622:
大神://处理返回的接收状态 这个好像没有监听到 遇 ...
android 发送短信的两种方式 -
PXY:
拦截部分地址,怎么写的for(int i=0;i<lis ...
判断是否登录的拦截器SessionFilter -
maotou1988:
Android控件之带清空按钮(功能)的AutoComplet ...
自定义AutoCompleteTextView -
yangmaolinpl:
希望有表例子更好。。。,不过也看明白了。
浅谈onInterceptTouchEvent、onTouchEvent与onTouch
原帖:
http://www.jianshu.com/p/f7add443cd32
Device Year Class 的主要功能是根据 CPU核数、时钟频率 以及 内存大小 对设备进行分级。
下表是 Facebook 公司提供的分级标准,其中 Year 栏表示分级结果。
以下类就是从Facebook 的开源项目Device Year Class中拿出来的
使用方法:
运行在Android设备上,启动本程序之后,在任何窗口可显示当前CPU工作频率等状态,显示当前电压电流电池容量等信息
https://github.com/will86/android-runninginfo
http://www.jianshu.com/p/f7add443cd32
Device Year Class 的主要功能是根据 CPU核数、时钟频率 以及 内存大小 对设备进行分级。
下表是 Facebook 公司提供的分级标准,其中 Year 栏表示分级结果。

以下类就是从Facebook 的开源项目Device Year Class中拿出来的
package com.yirui.youbao.util; import android.annotation.TargetApi; import android.app.ActivityManager; import android.content.Context; import android.os.Build; import java.io.*; /** * Helper class for accessing hardware specifications, including the number of CPU cores, CPU clock speed * and total available RAM. */ public class DeviceInfo { /** * The default return value of any method in this class when an * error occurs or when processing fails (Currently set to -1). Use this to check if * the information about the device in question was successfully obtained. */ public static final int DEVICEINFO_UNKNOWN = -1; /** * Reads the number of CPU cores from {@code /sys/devices/system/cpu/}. * * @return Number of CPU cores in the phone, or DEVICEINFO_UKNOWN = -1 in the event of an error. */ public static int getNumberOfCPUCores() { if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) { // Gingerbread doesn't support giving a single application access to both cores, but a // handful of devices (Atrix 4G and Droid X2 for example) were released with a dual-core // chipset and Gingerbread; that can let an app in the background run without impacting // the foreground application. But for our purposes, it makes them single core. return 1; } int cores; try { cores = new File("/sys/devices/system/cpu/").listFiles(CPU_FILTER).length; } catch (SecurityException e) { cores = DEVICEINFO_UNKNOWN; } catch (NullPointerException e) { cores = DEVICEINFO_UNKNOWN; } return cores; } private static final FileFilter CPU_FILTER = new FileFilter() { @Override public boolean accept(File pathname) { String path = pathname.getName(); //regex is slow, so checking char by char. if (path.startsWith("cpu")) { for (int i = 3; i < path.length(); i++) { if (path.charAt(i) < '0' || path.charAt(i) > '9') { return false; } } return true; } return false; } }; /** * Method for reading the clock speed of a CPU core on the device. Will read from either * {@code /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq} or {@code /proc/cpuinfo}. * * @return Clock speed of a core on the device, or -1 in the event of an error. */ public static int getCPUMaxFreqKHz() { int maxFreq = DEVICEINFO_UNKNOWN; try { for (int i = 0; i < getNumberOfCPUCores(); i++) { String filename = "/sys/devices/system/cpu/cpu" + i + "/cpufreq/cpuinfo_max_freq"; File cpuInfoMaxFreqFile = new File(filename); if (cpuInfoMaxFreqFile.exists()) { byte[] buffer = new byte[128]; FileInputStream stream = new FileInputStream(cpuInfoMaxFreqFile); try { stream.read(buffer); int endIndex = 0; //Trim the first number out of the byte buffer. while (buffer[endIndex] >= '0' && buffer[endIndex] <= '9' && endIndex < buffer.length) endIndex++; String str = new String(buffer, 0, endIndex); Integer freqBound = Integer.parseInt(str); if (freqBound > maxFreq) maxFreq = freqBound; } catch (NumberFormatException e) { //Fall through and use /proc/cpuinfo. } finally { stream.close(); } } } if (maxFreq == DEVICEINFO_UNKNOWN) { FileInputStream stream = new FileInputStream("/proc/cpuinfo"); try { int freqBound = parseFileForValue("cpu MHz", stream); freqBound *= 1000; //MHz -> kHz if (freqBound > maxFreq) maxFreq = freqBound; } finally { stream.close(); } } } catch (IOException e) { maxFreq = DEVICEINFO_UNKNOWN; //Fall through and return unknown. } return maxFreq; } /** * Calculates the total RAM of the device through Android API or /proc/meminfo. * * @param c - Context object for current running activity. * @return Total RAM that the device has, or DEVICEINFO_UNKNOWN = -1 in the event of an error. */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN) public static long getTotalMemory(Context c) { // memInfo.totalMem not supported in pre-Jelly Bean APIs. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo(); ActivityManager am = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE); am.getMemoryInfo(memInfo); if (memInfo != null) { return memInfo.totalMem; } else { return DEVICEINFO_UNKNOWN; } } else { long totalMem = DEVICEINFO_UNKNOWN; try { FileInputStream stream = new FileInputStream("/proc/meminfo"); try { totalMem = parseFileForValue("MemTotal", stream); totalMem *= 1024; } finally { stream.close(); } } catch (IOException e) { } return totalMem; } } /** * Helper method for reading values from system files, using a minimised buffer. * * @param textToMatch - Text in the system files to read for. * @param stream - FileInputStream of the system file being read from. * @return A numerical value following textToMatch in specified the system file. * -1 in the event of a failure. */ private static int parseFileForValue(String textToMatch, FileInputStream stream) { byte[] buffer = new byte[1024]; try { int length = stream.read(buffer); for (int i = 0; i < length; i++) { if (buffer[i] == '\n' || i == 0) { if (buffer[i] == '\n') i++; for (int j = i; j < length; j++) { int textIndex = j - i; //Text doesn't match query at some point. if (buffer[j] != textToMatch.charAt(textIndex)) { break; } //Text matches query here. if (textIndex == textToMatch.length() - 1) { return extractValue(buffer, j); } } } } } catch (IOException e) { //Ignore any exceptions and fall through to return unknown value. } catch (NumberFormatException e) { } return DEVICEINFO_UNKNOWN; } /** * Helper method used by {@link #parseFileForValue(String, FileInputStream) parseFileForValue}. Parses * the next available number after the match in the file being read and returns it as an integer. * @param index - The index in the buffer array to begin looking. * @return The next number on that line in the buffer, returned as an int. Returns * DEVICEINFO_UNKNOWN = -1 in the event that no more numbers exist on the same line. */ private static int extractValue(byte[] buffer, int index) { while (index < buffer.length && buffer[index] != '\n') { if (buffer[index] >= '0' && buffer[index] <= '9') { int start = index; index++; while (index < buffer.length && buffer[index] >= '0' && buffer[index] <= '9') { index++; } String str = new String(buffer, 0, start, index - start); return Integer.parseInt(str); } index++; } return DEVICEINFO_UNKNOWN; } }
package com.yirui.youbao.util; import java.util.ArrayList; import java.util.Collections; import android.content.Context; public class YearClass { // Year definitions public static final int CLASS_UNKNOWN = -1; public static final int CLASS_2008 = 2008; public static final int CLASS_2009 = 2009; public static final int CLASS_2010 = 2010; public static final int CLASS_2011 = 2011; public static final int CLASS_2012 = 2012; public static final int CLASS_2013 = 2013; public static final int CLASS_2014 = 2014; private static final long MB = 1024 * 1024; private static final int MHZ_IN_KHZ = 1000; private volatile static Integer mYearCategory; /** * Entry Point of YearClass. Extracts YearClass variable with memoizing. * Example usage: * <p> * <pre> * int yearClass = YearClass.get(context); * </pre> */ public static int get(Context c) { if (mYearCategory == null) { synchronized(YearClass.class) { if (mYearCategory == null) { mYearCategory = categorizeByYear(c); } } } return mYearCategory; } private static void conditionallyAdd(ArrayList<Integer> list, int value) { if (value != CLASS_UNKNOWN) { list.add(value); } } /** * Calculates the "best-in-class year" of the device. This represents the top-end or flagship * devices of that year, not the actual release year of the phone. For example, the Galaxy Duos * S was released in 2012, but its specs are very similar to the Galaxy S that was released in * 2010 as a then top-of-the-line phone, so it is a 2010 device. * * @return The year when this device would have been considered top-of-the-line. */ private static int categorizeByYear(Context c) { ArrayList<Integer> componentYears = new ArrayList<Integer>(); conditionallyAdd(componentYears, getNumCoresYear()); conditionallyAdd(componentYears, getClockSpeedYear()); conditionallyAdd(componentYears, getRamYear(c)); if (componentYears.isEmpty()) return CLASS_UNKNOWN; Collections.sort(componentYears); if ((componentYears.size() & 0x01) == 1) { // Odd number; pluck the median. return componentYears.get(componentYears.size() / 2); } else { // Even number. Average the two "center" values. int baseIndex = componentYears.size() / 2 - 1; // There's an implicit rounding down in here; 2011.5 becomes 2011. return componentYears.get(baseIndex) + (componentYears.get(baseIndex + 1) - componentYears.get(baseIndex)) / 2; } } /** * Calculates the year class by the number of processor cores the phone has. * Evaluations are based off the table below: * <table border="1"> * <thead> * <tr><th width="50%">Amount</th><th>Year</th></tr> * <thead> * <tbody> * <tr><td>>4 or More</td><td>2012</td></tr> * <tr><td>2 or 3</td><td>2011</td></tr> * <tr><td>1</td><td>2008</td></tr> * </tbody> * </table> * * @return the year in which top-of-the-line phones had the same number of processors as this phone. */ private static int getNumCoresYear() { int cores = DeviceInfo.getNumberOfCPUCores(); if (cores < 1) return CLASS_UNKNOWN; if (cores == 1) return CLASS_2008; if (cores <= 3) return CLASS_2011; return CLASS_2012; } /** * Calculates the year class by the clock speed of the cores in the phone. * Evaluations are based off the table below: * <table border="1"> * <thead> * <tr><th width="50%">Amount</th><th>Year</th></tr> * <thead> * <tbody> * <tr><td>>2GHz</td><td>2014</td></tr> * <tr><td><=2GHz</td><td>2013</td></tr> * <tr><td><=1.5GHz</td><td>2012</td></tr> * <tr><td><=1.2GHz</td><td>2011</td></tr> * <tr><td><=1GHz</td><td>2010</td></tr> * <tr><td><=600MHz</td><td>2009</td></tr> * <tr><td><=528MHz</td><td>2008</td></tr> * </tbody> * </table> * * @return the year in which top-of-the-line phones had the same clock speed. */ private static int getClockSpeedYear() { long clockSpeedKHz = DeviceInfo.getCPUMaxFreqKHz(); if (clockSpeedKHz == DeviceInfo.DEVICEINFO_UNKNOWN) return CLASS_UNKNOWN; // These cut-offs include 20MHz of "slop" because my "1.5GHz" Galaxy S3 reports // its clock speed as 1512000. So we add a little slop to keep things nominally correct. if (clockSpeedKHz <= 528 * MHZ_IN_KHZ) return CLASS_2008; if (clockSpeedKHz <= 620 * MHZ_IN_KHZ) return CLASS_2009; if (clockSpeedKHz <= 1020 * MHZ_IN_KHZ) return CLASS_2010; if (clockSpeedKHz <= 1220 * MHZ_IN_KHZ) return CLASS_2011; if (clockSpeedKHz <= 1520 * MHZ_IN_KHZ) return CLASS_2012; if (clockSpeedKHz <= 2020 * MHZ_IN_KHZ) return CLASS_2013; return CLASS_2014; } /** * Calculates the year class by the amount of RAM the phone has. * Evaluations are based off the table below: * <table border="1"> * <thead> * <tr><th width="50%">Amount</th><th>Year</th></tr> * <thead> * <tbody> * <tr><td>>2GB</td><td>2014</td></tr> * <tr><td><=2GB</td><td>2013</td></tr> * <tr><td><=1.5GB</td><td>2012</td></tr> * <tr><td><=1GB</td><td>2011</td></tr> * <tr><td><=512MB</td><td>2010</td></tr> * <tr><td><=256MB</td><td>2009</td></tr> * <tr><td><=128MB</td><td>2008</td></tr> * </tbody> * </table> * * @return the year in which top-of-the-line phones had the same amount of RAM as this phone. */ private static int getRamYear(Context c) { long totalRam = DeviceInfo.getTotalMemory(c); if (totalRam <= 0) return CLASS_UNKNOWN; if (totalRam <= 192 * MB) return CLASS_2008; if (totalRam <= 290 * MB) return CLASS_2009; if (totalRam <= 512 * MB) return CLASS_2010; if (totalRam <= 1024 * MB) return CLASS_2011; if (totalRam <= 1536 * MB) return CLASS_2012; if (totalRam <= 2048 * MB) return CLASS_2013; return CLASS_2014; } }
使用方法:
import android.app.Activity; import android.content.SharedPreferences; import android.os.AsyncTask; import android.os.Bundle; import android.widget.TextView; import com.facebook.device.yearclass.YearClass; public class MainActivity extends Activity { private static final String PREF_FILE = "YearClass"; private static final String PREF_NAME = "yearclass"; private TextView mYearClass; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); GetOrComputeYearClass findYearClass = new GetOrComputeYearClass(); findYearClass.execute(); mYearClass = (TextView) findViewById(R.id.year_class); } private class GetOrComputeYearClass extends AsyncTask<Void, Void, Integer> { @Override protected Integer doInBackground(Void... voids) { int yearClass = YearClass.CLASS_UNKNOWN; SharedPreferences prefs = getSharedPreferences(PREF_FILE, 0); if (prefs.contains(PREF_NAME)) { yearClass = prefs.getInt(PREF_NAME, YearClass.CLASS_UNKNOWN); } //Try again if device was previously unknown. if (yearClass == YearClass.CLASS_UNKNOWN) { yearClass = YearClass.get(getApplicationContext()); SharedPreferences.Editor editor = prefs.edit(); editor.putInt(PREF_NAME, yearClass); editor.apply(); } return yearClass; } @Override protected void onPostExecute(Integer yearClass) { //update UI mYearClass.setText(Integer.toString(yearClass)); } } }
运行在Android设备上,启动本程序之后,在任何窗口可显示当前CPU工作频率等状态,显示当前电压电流电池容量等信息
https://github.com/will86/android-runninginfo
发表评论
-
某些android手机获取不到IMEI问题
2018-08-21 14:17 7677某些山寨机可能拿不到IMEI 如果非要IMEI可以模拟一个 ... -
APK安装成功后点击"打开"再按Home键应用会重启的问题
2018-08-21 14:13 2804安装系统SD卡里面的apk或者原有的程序更新版本的时候, ... -
使用volley链接Https地址时报SSLHandshakeException
2018-08-21 14:06 2199在真实设备上出现以下错误 ︰ Volley error: ... -
PhotoView+Viewpager双指缩放的时候出现pointerIndex out of range问题
2017-07-10 14:30 4288PhotoView+Viewpager开发图集效果的时候,在某 ... -
Android6.0权限封装
2017-04-01 12:04 1604简介 Android6.0中对权限分为了一般权限和危险权限。 ... -
实现点击 WebView 中的图片,调用原生控件展示图片
2017-04-01 11:14 2845现在有很多时候,我们的 App 都进行了混合开发,而最简单,最 ... -
Android 方法引用数超过 65535 优雅解决
2017-03-31 09:37 1590随着应用不断迭代更新,业务线的扩展,应用越来越大(比如:集成了 ... -
android引用资源@与属性?备忘单
2017-03-30 10:09 1313几天前我偶然发现了我A ... -
ViewPager 与SwipeRefreshLayout,RecyclerView,ScrollView滑动冲突解决方法
2017-03-30 09:55 6600ViewPager 作为一个横向滚动的控件, 在 ViewGr ... -
Android中一些你可能没注意的小效果实现
2017-02-15 21:09 0http://www.see-source.com/blog/ ... -
Android热修复:Andfix和Hotfix,两种方案的比较与实现
2017-02-15 21:00 0http://www.see-source.com/blog/ ... -
Android 从网页中跳转到本地App
2017-01-11 09:27 1910我们在使用微信、QQ、京东等app的时候,会发现有时候通过他们 ... -
Activity的启动模式和onNewIntent
2016-12-28 09:10 1361一、启动模式介绍 启 ... -
android5.0使用Notification报RemoteServiceException的解决办法
2016-08-31 16:13 11593有时android5.0下使用Notification会报如下 ... -
RecyclerView 中的 item 如何居中问题
2016-05-18 09:52 12613一个很简单的Item布局,我只要让它由上而下排列,文字居中 ... -
sqlite3:not found 解决方法
2015-12-08 16:03 2578最最最重要,先root你的手机吧 sqlite3 为一个可 ... -
隐藏底部虚拟键NavigationBar实现全屏
2015-10-08 17:20 9893import android.app.Activity; ... -
服务端执行慢或网络延迟时,Volley多次发送请求的问题
2015-07-27 15:40 7043原文: Android Volley double post ... -
android点滴5
2015-04-10 17:32 2078一些小效果的实现 http://www.see-source. ... -
SwipeRefreshLayout和ListView的EmptyView共存冲突的问题
2015-01-20 11:47 18683SwipeRefreshLayout是android官方的下拉 ...
相关推荐
本文实例讲述了Android获取设备CPU核数、时钟频率以及内存大小的方法。分享给大家供大家参考,具体如下: 因项目需要,分析了一下 Facebook 的开源项目 – Device Year Class。 Device Year Class 的主要功能是根据 ...
资源内项目源码是来自个人的毕业设计,代码都测试ok,包含源码、数据集、可视化页面和部署说明,可产生核心指标曲线图、混淆矩阵、F1分数曲线、精确率-召回率曲线、验证集预测结果、标签分布图。都是运行成功后才上传资源,毕设答辩评审绝对信服的保底85分以上,放心下载使用,拿来就能用。包含源码、数据集、可视化页面和部署说明一站式服务,拿来就能用的绝对好资源!!! 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、大作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.txt文件,仅供学习参考, 切勿用于商业用途。
wrf转mp4播放器1.1.1
内容概要:本文档详细介绍了如何在Simulink中设计一个满足特定规格的音频带ADC(模数转换器)。首先选择了三阶单环多位量化Σ-Δ调制器作为设计方案,因为这种结构能在音频带宽内提供高噪声整形效果,并且多位量化可以降低量化噪声。接着,文档展示了具体的Simulink建模步骤,包括创建模型、添加各个组件如积分器、量化器、DAC反馈以及连接它们。此外,还进行了参数设计与计算,特别是过采样率和信噪比的估算,并引入了动态元件匹配技术来减少DAC的非线性误差。性能验证部分则通过理想和非理想的仿真实验评估了系统的稳定性和各项指标,最终证明所设计的ADC能够达到预期的技术标准。 适用人群:电子工程专业学生、从事数据转换器研究或开发的技术人员。 使用场景及目标:适用于希望深入了解Σ-Δ调制器的工作原理及其在音频带ADC应用中的具体实现方法的人群。目标是掌握如何利用MATLAB/Simulink工具进行复杂电路的设计与仿真。 其他说明:文中提供了详细的Matlab代码片段用于指导读者完成整个设计流程,同时附带了一些辅助函数帮助分析仿真结果。
国网台区终端最新规范
《基于YOLOv8的智慧农业水肥一体化控制系统》(包含源码、可视化界面、完整数据集、部署教程)简单部署即可运行。功能完善、操作简单,适合毕设或课程设计
GSDML-V2.33-LEUZE-AMS3048i-20170622.xml
微信小程序项目课程设计,包含LW+ppt
微信小程序项目课程设计,包含LW+ppt
终端运行进度条脚本
幼儿园预防肺结核教育培训课件资料
python,python相关资源
《基于YOLOv8的智慧校园电动车充电桩状态监测系统》(包含源码、可视化界面、完整数据集、部署教程)简单部署即可运行。功能完善、操作简单,适合毕设或课程设计
deepseek 临床之理性软肋.pdf
SM2258XT量产工具(包含16种程序),固态硬盘量产工具使用
RecyclerView.zip
水务大脑让水务运营更智能(23页)
资源内项目源码是来自个人的毕业设计,代码都测试ok,包含源码、数据集、可视化页面和部署说明,可产生核心指标曲线图、混淆矩阵、F1分数曲线、精确率-召回率曲线、验证集预测结果、标签分布图。都是运行成功后才上传资源,毕设答辩评审绝对信服的保底85分以上,放心下载使用,拿来就能用。包含源码、数据集、可视化页面和部署说明一站式服务,拿来就能用的绝对好资源!!! 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、大作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.txt文件,仅供学习参考, 切勿用于商业用途。
大众捷达轿车前轮制动器设计
《基于YOLOv8的智能工厂压缩空气泄漏检测系统》(包含源码、可视化界面、完整数据集、部署教程)简单部署即可运行。功能完善、操作简单,适合毕设或课程设计