添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
儒雅的热带鱼  ·  android ...·  昨天    · 
苦闷的烤红薯  ·  兰州大学档案馆·  8 月前    · 
年轻有为的滑板  ·  Mutex in std::sync - Rust·  1 年前    · 
非常酷的双杠  ·  篁城竹簾官方網站·  1 年前    · 
腼腆的馒头  ·  ElringKlinger AG - ...·  1 年前    · 
  1. /**
  2. *
  3. * [获取cpu类型和架构]
  4. *
  5. * @return
  6. * 三个参数类型的数组,第一个参数标识是不是ARM架构,第二个参数标识是V6还是V7架构,第三个参数标识是不是neon指令集
  7. */
  8. public static Object[] getCpuArchitecture() {
  9. if ((Integer) mArmArchitecture[ 1 ] != - 1 ) {
  10. return mArmArchitecture;
  11. }
  12. try {
  13. InputStream is = new FileInputStream( "/proc/cpuinfo" );
  14. InputStreamReader ir = new InputStreamReader(is);
  15. BufferedReader br = new BufferedReader(ir);
  16. try {
  17. String nameProcessor = "Processor" ;
  18. String nameFeatures = "Features" ;
  19. String nameModel = "model name" ;
  20. String nameCpuFamily = "cpu family" ;
  21. while ( true ) {
  22. String line = br.readLine();
  23. String[] pair = null ;
  24. if (line == null ) {
  25. break ;
  26. }
  27. pair = line.split( ":" );
  28. if (pair.length != 2 )
  29. continue ;
  30. String key = pair[ 0 ].trim();
  31. String val = pair[ 1 ].trim();
  32. if (key.compareTo(nameProcessor) == 0 ) {
  33. String n = "" ;
  34. for ( int i = val.indexOf( "ARMv" ) + 4 ; i < val.length(); i++) {
  35. String temp = val.charAt(i) + "" ;
  36. if (temp.matches( "\\d" )) {
  37. n += temp;
  38. } else {
  39. break ;
  40. }
  41. }
  42. mArmArchitecture[ 0 ] = "ARM" ;
  43. mArmArchitecture[ 1 ] = Integer.parseInt(n);
  44. continue ;
  45. }
  46. if (key.compareToIgnoreCase(nameFeatures) == 0 ) {
  47. if (val.contains( "neon" )) {
  48. mArmArchitecture[ 2 ] = "neon" ;
  49. }
  50. continue ;
  51. }
  52. if (key.compareToIgnoreCase(nameModel) == 0 ) {
  53. if (val.contains( "Intel" )) {
  54. mArmArchitecture[ 0 ] = "INTEL" ;
  55. mArmArchitecture[ 2 ] = "atom" ;
  56. }
  57. continue ;
  58. }
  59. if (key.compareToIgnoreCase(nameCpuFamily) == 0 ) {
  60. mArmArchitecture[ 1 ] = Integer.parseInt(val);
  61. continue ;
  62. }
  63. }
  64. } finally {
  65. br.close();
  66. ir.close();
  67. is.close();
  68. }
  69. } catch (Exception e) {
  70. e.printStackTrace();
  71. }
  72. return mArmArchitecture;
  73. }
* [获取cpu类型和架构] * @return * 三个参数类型的数组,第一个参数标识是不是ARM架构,第二个参数标识是V6还是V7架构,第三个参数标识是不是neon指令集 public static Object[] getCpuArchitecture() { if ((Integer) mArmArchitecture[1] != -1) { return mArmArchitecture; try { InputStream is = new FileInputStream("/proc/cpuinfo"); InputStreamReader ir = new InputStreamReader(is); BufferedReader br = new BufferedReader(ir); try { String nameProcessor = "Processor"; String nameFeatures = "Features"; String nameModel = "model name"; String nameCpuFamily = "cpu family"; while (true) { String line = br.readLine(); String[] pair = null; if (line == null) { break; pair = line.split(":"); if (pair.length != 2) continue; String key = pair[0].trim(); String val = pair[1].trim(); if (key.compareTo(nameProcessor) == 0) { String n = ""; for (int i = val.indexOf("ARMv") + 4; i < val.length(); i++) { String temp = val.charAt(i) + ""; if (temp.matches("\\d")) { n += temp; } else { break; mArmArchitecture[0] = "ARM"; mArmArchitecture[1] = Integer.parseInt(n); continue; if (key.compareToIgnoreCase(nameFeatures) == 0) { if (val.contains("neon")) { mArmArchitecture[2] = "neon"; continue; if (key.compareToIgnoreCase(nameModel) == 0) { if (val.contains("Intel")) { mArmArchitecture[0] = "INTEL"; mArmArchitecture[2] = "atom"; continue; if (key.compareToIgnoreCase(nameCpuFamily) == 0) { mArmArchitecture[1] = Integer.parseInt(val); continue; } finally { br.close(); ir.close(); is.close(); } catch (Exception e) { e.printStackTrace(); return mArmArchitecture;
调用的该函数的示例方法
  1. /*
  2. * 获取FFpeg解码库的名称(如果是插件,会涉及到一个向下兼容的问题,例如:如果当前cpu是V7neo,而又没有neon的解码库,必须要做向下兼容出来
  3. * ,如果有V7的库就加载V7的库,有V6的库就加载V6的)
  4. */
  5. public static String getFFmpegLibName(Context context) {
  6. if (LIB_FFMPEG_NAME != null ) {
  7. return LIB_FFMPEG_NAME;
  8. }
  9. Object[] arch = getCpuArchitecture();
  10. String libDir = getNativeLibraryDir(context);
  11. String libSysDir = "/system/lib" ;
  12. if ( "ARM" .equals(arch[ 0 ])) {
  13. try {
  14. String ffmpeg = String.format( "ffmpeg-%d%s" , (Integer) arch[ 1 ], (String) arch[ 2 ]);
  15. if (isFileExist(libDir + "/lib" + ffmpeg + ".so" ) || isFileExist(libSysDir + "/lib" + ffmpeg + ".so" )) {
  16. return ffmpeg;
  17. } else {
  18. boolean isV7NeonCpu = "neon" .equals(arch[ 2 ]);
  19. boolean isV7 = ((Integer) arch[ 1 ]) == 7 && "" .equals(arch[ 2 ]);
  20. boolean isV6 = ((Integer) arch[ 1 ]) == 6 ;
  21. if (isV7NeonCpu) {
  22. if (isFileExist(libDir + "/libffmpeg-7neon.so" )
  23. || isFileExist(libSysDir + "/libffmpeg-7neon.so" )) {
  24. LIB_FFMPEG_NAME = "ffmpeg-7neon" ;
  25. return "ffmpeg-7neon" ;
  26. } else if (isFileExist(libDir + "/libffmpeg-7.so" )
  27. || isFileExist(libSysDir + "/libffmpeg-7.so" )) {
  28. LIB_FFMPEG_NAME = "ffmpeg-7" ;
  29. return "ffmpeg-7" ;
  30. } else if (isFileExist(libDir + "/libffmpeg-6.so" )
  31. || isFileExist(libSysDir + "/libffmpeg-6.so" )) {
  32. LIB_FFMPEG_NAME = "ffmpeg-6" ;
  33. return "ffmpeg-6" ;
  34. }
  35. } else if (isV7) {
  36. if (isFileExist(libDir + "/libffmpeg-7.so" ) || isFileExist(libSysDir + "/libffmpeg-7.so" )) {
  37. LIB_FFMPEG_NAME = "ffmpeg-7" ;
  38. return "ffmpeg-7" ;
  39. } else if (isFileExist(libDir + "/libffmpeg-6.so" )
  40. || isFileExist(libSysDir + "/libffmpeg-6.so" )) {
  41. LIB_FFMPEG_NAME = "ffmpeg-6" ;
  42. return "ffmpeg-6" ;
  43. }
  44. } else if (isV6) {
  45. if (isFileExist(libDir + "/libffmpeg-6.so" ) || isFileExist(libSysDir + "/libffmpeg-6.so" )) {
  46. LIB_FFMPEG_NAME = "ffmpeg-6" ;
  47. return "ffmpeg-6" ;
  48. }
  49. }
  50. }
  51. } catch (Exception e) {
  52. e.printStackTrace();
  53. }
  54. } else if ( "INTEL" .equals(arch[ 0 ])) {
  55. if (isFileExist(libDir + "/libffmpeg-x86atom.so" ) || isFileExist(libSysDir + "/libffmpeg-x86atom.so" )) {
  56. LIB_FFMPEG_NAME = "ffmpeg-x86atom" ;
  57. return "ffmpeg-x86atom" ;
  58. }
  59. }
  60. LIB_FFMPEG_NAME = null ;
  61. return null ;
  62. }
String CPU _ABI = android .os.Build. CPU _ABI; Log.i("wyn_ cpu "," CPU _ABI = "+ CPU _ABI); String
Android 获取 系统 cpu 信息,内存,版本,电量等信息 1、 CPU 频率, CPU 信息:/proc/ cpu info和/proc/stat 通过读取文件/proc/ cpu info系统 CPU 类型 等多种信息。读取/proc/stat 所有 CPU 活动的信息来计算 CPU 使用率 下面我们就来讲讲如何通过代码来 获取 CPU 频率: 代码如下:package com.orange. cpu ;import java.io.BufferedReader;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.IOExce
文章参照自:http://www.2cto.com/kf/201206/134236.html 在 Android 中,我们可以通过读取一些系统文件来获得 手机 cpu 信息( CPU 名字和 CPU 主频)。 具体请参照实例1. package edu.cdut