判断Android设备是平板还是手机的方法
Integer.parseInt( android.os.Build.VERSION.SDK) > 10 //android3.0以上----平板
Integer.parseInt( android.os.Build.VERSION.SDK) > 6 //android2.1以上----手机
获取Android设备型号和系统版本号
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView textView = (TextView) findViewById(R.id.text);
textView.setText("产品 Model: " + android.os.Build.MODEL + "nAPI: " + android.os.Build.VERSION.SDK + "n系统版本: " + android.os.Build.VERSION.RELEASE);
}
获取Android设备的mac地址的方法
1、首先需要在AndroidManifest.xml文件中添加权限,代码如下:
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
2、Java代码(必须在Activity中使用)
public String getLocalMacAddress() {
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wifi.getConnectionInfo();
return info.getMacAddress();
}
获取Android设备的IP地址的方法
public String getLocalIpAddress() {
try {
for (Enumeration<NetworkInterface> en = NetworkInterface .getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf .getInetAddresses(); enumIpAddr.hasMoreElements();) { <br />
InetAddress inetAddress = enumIpAddr.nextElement(); <br />
if (!inetAddress.isLoopbackAddress()) { <br />
return inetAddress.getHostAddress().toString(); <br />
} <br />
} <br />
} <br />
} catch (SocketException ex) { <br />
Log.e("WifiPreference IpAddress", ex.toString()); <br />
} <br />
return null; <br />
}
如果使用的是模拟器测试上面的程序,mac地址和IP地址所得到的值为null
获取Android设备屏幕的分辨率
public String getWeithAndHeight() {
//这种方式在service中无法使用,
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels; //宽
int height = dm.heightPixels; //高
//在service中也能得到高和宽
WindowManager mWindowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
width = mWindowManager.getDefaultDisplay().getWidth();
height = mWindowManager.getDefaultDisplay().getHeight();
String strPM = "设备屏幕分辨率为:" + width + " * " + height;
return strPM;
}
注:以上内容摘录自http://www.52youpiao.com/it/post/android_os_mac.html