600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > adb 查看gpu_获取android 设备的cpu gpu信息 mac地址

adb 查看gpu_获取android 设备的cpu gpu信息 mac地址

时间:2018-11-25 12:58:43

相关推荐

adb 查看gpu_获取android 设备的cpu gpu信息 mac地址

1.获取cpu信息:cpu信息存在于/proc/cpuinfo文件下,adb shell 进去后用 cat /proc/cpuinfo 可以查看

private String getCpuInfo() {

FileReader fr = null;

BufferedReader br = null;

String text=null;

StringBuilder sb=new StringBuilder();

try {

fr = new FileReader("/proc/cpuinfo");

br = new BufferedReader(fr);

text = br.readLine();

sb.append(text);

while (text!=null) {

text = br.readLine();

sb.append("\r\n");

sb.append(text);

}

//String[] array = text.split(":\\s+", 2);

return sb.toString();

//return array[1];

} catch (FileNotFoundException e) {

Log.d("you", "getCpuInfo FileNotFoundException e:"+e.getMessage() );

} catch (IOException e) {

Log.d("you", "getCpuInfo IOException e:"+e.getMessage() );

} finally {

try {

fr.close();

br.close();

} catch (IOException e) {

e.printStackTrace();

}

}

Log.d("you", "getCpuInfo return space" );

return "";

}

2.获取gpu信息 Android的GPU信息需要通过OpenGL来获取

实现一个GLSurfaceView.Renderer 将renderer设置给GLSurfaceView 在Activity中this.setContentView(glView);

import javax.microedition.khronos.egl.EGLConfig;

import javax.microedition.khronos.opengles.GL10;

import android.app.Activity;

import android.content.Context;

import android.opengl.GLSurfaceView;

import android.os.Bundle;

import android.util.Log;

public class DemoActivity extends Activity {

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

GLSurfaceView glView = new DemoGLSurfaceView(this);

this.setContentView(glView);

}

@Override

protected void onResume() {

super.onResume();

}

public class DemoGLSurfaceView extends GLSurfaceView {

DemoRenderer mRenderer;

public DemoGLSurfaceView(Context context) {

super(context);

setEGLConfigChooser(8, 8, 8, 8, 0, 0);

mRenderer = new DemoRenderer();

setRenderer(mRenderer);

}

}

public class DemoRenderer implements GLSurfaceView.Renderer {

public void onSurfaceCreated(GL10 gl, EGLConfig config) {

Log.d("SystemInfo",

"GL_RENDERER = " + gl.glGetString(GL10.GL_RENDERER));

Log.d("SystemInfo", "GL_VENDOR = " + gl.glGetString(GL10.GL_VENDOR));

Log.d("SystemInfo",

"GL_VERSION = " + gl.glGetString(GL10.GL_VERSION));

Log.i("SystemInfo",

"GL_EXTENSIONS = " + gl.glGetString(GL10.GL_EXTENSIONS));

}

public void onDrawFrame(GL10 arg0) {

}

public void onSurfaceChanged(GL10 arg0, int arg1, int arg2) {

}

}

}

在实际中可以通过在布局中添加一个GLSurfaceView,当获取到信息后将其移除。

3.获取mac地址:分为有线和wifi

private String loadFileAsString(String filePath) throws java.io.IOException{

StringBuffer fileData = new StringBuffer(1000);

BufferedReader reader = new BufferedReader(new FileReader(filePath));

char[] buf = new char[1024];

int numRead=0;

while((numRead=reader.read(buf)) != -1){

String readData = String.valueOf(buf, 0, numRead);

fileData.append(readData);

}

reader.close();

return fileData.toString();

}

/*

* Get MacAddress

*/

private String getMacAddress(String name){//name可能传入eth0 eth1 eth2............

try {

return loadFileAsString("/sys/class/net/"+name+ "/address")

.toUpperCase().substring(0, 17);

} catch (IOException e) {

e.printStackTrace();

return null;

}catch (Exception e) {

return null;

}

}

private String getMacFromWifi(){

WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);

int state = wifi.getWifiState();//如果不成功可能尝试去打开wifi再来获取

if(state == WifiManager.WIFI_STATE_ENABLED ||state == WifiManager.WIFI_STATE_ENABLING ){

WifiInfo info = wifi.getConnectionInfo();

if(info==null){

return null;

}

return info.getMacAddress();

}

return null;

} wifi也可以获取有线的方式(读取文件的方式)获取,wifi mac地址的文件是:/sys/class/net/wlan0/address

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。