我手机的关于手机界面:
说明:
其中手机型号、Android版本、软件版本通过系统Build类得到,处理器信息、内核版本通过读取系统文件得到,基带版本信息通过反射得到。
源码:
package com.example.shen.phoneinfo; import android.app.Activity; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.lang.reflect.Method; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Log.e("phoneInfo", "MODEL:" + android.os.Build.MODEL); Log.e("phoneInfo", "CPUInfo:"+getCPUInfo()); Log.e("phoneInfo", "VERSION_RELEASE:"+android.os.Build.VERSION.RELEASE); Log.e("phoneInfo", "VERSION_SDK:"+android.os.Build.VERSION.SDK_INT + ""); Log.e("phoneInfo", "BaseBandVersion:"+getBaseBandVersion()); Log.e("phoneInfo", "KernelVersion:"+getKernelVersion()); Log.e("phoneInfo", "ID:" + android.os.Build.ID); } /** * 获得处理器信息 * @return String */ public String getCPUInfo() { try { FileReader fileReader = new FileReader("/proc/cpuinfo"); BufferedReader bufferedReader = new BufferedReader(fileReader); String info; while ((info = bufferedReader.readLine()) != null) { String[] array = info.split(":"); if(array[0].trim().equals("Hardware")) { return array[1]; } } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; } /** *获得基带版本 * @return String */ public String getBaseBandVersion() { String version = ""; try { Class clazz= Class.forName("android.os.SystemProperties"); Object object = clazz.newInstance(); Method method = clazz.getMethod("get", new Class[]{String.class, String.class}); Object result = method.invoke(object, new Object[]{"gsm.version.baseband", "no message"}); version = (String) result; } catch (Exception e) { } return version; } /** * 获得内核版本 * @return String */ public String getKernelVersion() { Process process = null; String kernelVersion = ""; try { process = Runtime.getRuntime().exec("cat /proc/version"); } catch (IOException e) { e.printStackTrace(); } InputStream inputStream = process.getInputStream(); InputStreamReader inputStreamReader = new InputStreamReader(inputStream); BufferedReader bufferedReader = new BufferedReader(inputStreamReader, 8 * 1024); String result = ""; String info; try { while ((info = bufferedReader.readLine()) != null) { result += info; } } catch (IOException e) { e.printStackTrace(); } try { if (result != "") { String keyword = "version "; int index = result.indexOf(keyword); info = result.substring(index + keyword.length()); index = info.indexOf(" "); kernelVersion = info.substring(0, index); } } catch (IndexOutOfBoundsException e) { e.printStackTrace(); } return kernelVersion; } }
运行结果:
/proc/cpuinfo文件截图
/proc/version文件截图
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-12 22:36:51