3377635c83029c376f7e2L205">205
/**
* 获取IPV6地址
*/
public String getIPV6() throws SocketException {
String ipv6 = null;
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
String ipv6s = inetAddress.getHostAddress();
if (ipv6s.contains("::") && ipv6s.contains("%")) {
ipv6 = ipv6s.substring(0, ipv6s.indexOf("%"));
if (InetAddressUtils.isIPv6Address(ipv6)) {
return ipv6;
}
}
}
}
return null;
}
/**
* 获取IPV4地址
*/
public String getIPV4() throws SocketException {
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress() && InetAddressUtils.isIPv4Address(inetAddress.getHostAddress())) {
return inetAddress.getHostAddress().toString();
}
}
}
return null;
}
}
package com.ai.ipu.mobile.plugin;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
import java.util.TimeZone;
import org.json.JSONArray;
import android.content.Context;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import com.ai.ipu.mobile.frame.IIpuMobile;
import com.ai.ipu.mobile.frame.plugin.Plugin;
import com.ai.ipu.mobile.ui.UiTool;
import com.ai.ipu.mobile.util.FuncConstant;
import com.ai.ipu.mobile.util.Messages;
import com.ailk.common.data.IData;
import com.ailk.common.data.impl.DataMap;
import com.mashape.relocation.conn.util.InetAddressUtils;
public class MobileInfo extends Plugin {
public String platform = "Android";
public MobileInfo(IIpuMobile ipumobile) {
super(ipumobile);
}
public void getTerminalType(JSONArray params) throws Exception {
callback("a");// 终端类型为android
}
/**
* 获取系统信息
*
* @param key
* @return
* @throws Exception
*/
public void getSysInfo(JSONArray params) throws Exception {
if (params.length() < 1) {
throw new Exception(Messages.EXCEPTION_PARAM);
}
String key = params.getString(0).toUpperCase();
if (key.equals(FuncConstant.PLATFORM)) {
callback(this.getPlatform());
}
else if (key.equals(FuncConstant.IMEI)) {
callback(this.getImei());
}
else if (key.equals(FuncConstant.UUID)) {
callback(this.getUuid());
}
else if (key.equals(FuncConstant.SIMNUMBER)) {
callback(this.getSimNumber());
}
else if (key.equals(FuncConstant.IMSI)) {
callback(this.getImsi());
}
else if (key.equals(FuncConstant.OSVERSION)) {
callback(this.getOSVersion());
}
else if (key.equals(FuncConstant.SDKVERSION)) {
callback(this.getSDKVersion());
}
else if (key.equals(FuncConstant.TIMEZONEID)) {
callback(this.getTimeZoneID());
}
else if (key.equals(FuncConstant.MODEL)) {
callback(this.getModel());
}
else if (key.equals(FuncConstant.MANUFACTURER)) {
callback(this.getManufacturer());
}
else if (key.equals(FuncConstant.BRAND)) {
callback(this.getBrand());
}
else if (key.equals(FuncConstant.PRODUCTNAME)) {
callback(this.getProductName());
}
else if(key.equals(FuncConstant.STATUSBARHEIGHT)){
callback(this.getStatusBarHeight());
}
else if (key.equals(FuncConstant.ALL)) {
callback(this.getAll());
}
else {
callback(Messages.NO_INFO);
}
}
public String getAll() throws SocketException {
IData data = new DataMap();
data.put(FuncConstant.PLATFORM, this.getPlatform());
data.put(FuncConstant.IMEI, this.getImei());
data.put(FuncConstant.UUID, this.getUuid());
data.put(FuncConstant.SIMNUMBER, this.getSimNumber());
data.put(FuncConstant.IMSI, this.getImsi());
data.put(FuncConstant.OSVERSION, this.getOSVersion());
data.put(FuncConstant.SDKVERSION, this.getSDKVersion());
data.put(FuncConstant.TIMEZONEID, this.getTimeZoneID());
data.put(FuncConstant.MODEL, this.getModel());
data.put(FuncConstant.MANUFACTURER, this.getManufacturer());
data.put(FuncConstant.MAC, this.getMac());
data.put(FuncConstant.IP, this.getIP());
data.put(FuncConstant.IPV6, this.getIPV6());
data.put(FuncConstant.BRAND, this.getBrand());
data.put(FuncConstant.PRODUCTNAME, this.getProductName());
return data.toString();
}
public String getPlatform() {
return platform;
}
public String getUuid() {
String uuid = Settings.Secure.getString(this.context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
return uuid;
}
public String getTelNumber() {
TelephonyManager manager = (TelephonyManager) this.context.getSystemService(Context.TELEPHONY_SERVICE);
return manager.getLine1Number();
}
public String getImei() {
TelephonyManager manager = (TelephonyManager) this.context.getSystemService(Context.TELEPHONY_SERVICE);
return manager.getDeviceId();
}
public String getSimNumber() {
TelephonyManager manager = (TelephonyManager) this.context.getSystemService(Context.TELEPHONY_SERVICE);
return manager.getSimSerialNumber();
}
public String getImsi() {
TelephonyManager manager = (TelephonyManager) this.context.getSystemService(Context.TELEPHONY_SERVICE);
return manager.getSubscriberId();
}
public String getOSVersion() {
String osversion = android.os.Build.VERSION.RELEASE;
return osversion;
}
public String getSDKVersion() {
String sdkversion = android.os.Build.VERSION.SDK;
return sdkversion;
}
public String getTimeZoneID() {
TimeZone tz = TimeZone.getDefault();
return (tz.getID());
}
public String getManufacturer() {
String manufacturer = android.os.Build.MANUFACTURER;
return manufacturer;
}
public String getBrand() {
String brand = android.os.Build.BRAND;
return brand;
}
public String getModel() {
String model = android.os.Build.MODEL;
return model;
}
public String getProductName() {
String productname = android.os.Build.PRODUCT;
return productname;
}
/***************** network *************************/
public void getNetInfo(JSONArray params) throws Exception {
if (params.length() < 1) {
throw new Exception(Messages.EXCEPTION_PARAM);
}
String key = params.getString(0).toUpperCase();
if (key.equals(FuncConstant.MAC)) {
callback(getMac());
}
else if (key.equals(FuncConstant.IP)) {
callback(getIP());
}
else if (key.equals(FuncConstant.IPV4)) {
callback(getIPV4());
}
else if (key.equals(FuncConstant.IPV6)) {
callback(getIPV6());
}
}
public String getMac() {
WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wifi.getConnectionInfo();
return info.getMacAddress();
}
public String getIP() throws SocketException {
return getIPV4();
}
/**
* 获取IPV6地址
*/
public String getIPV6() throws SocketException {
String ipv6 = null;
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
String ipv6s = inetAddress.getHostAddress();
if (ipv6s.contains("::") && ipv6s.contains("%")) {
ipv6 = ipv6s.substring(0, ipv6s.indexOf("%"));
if (InetAddressUtils.isIPv6Address(ipv6)) {
return ipv6;
}
}
}
}
return null;
}
/**
* 获取IPV4地址
*/
public String getIPV4() throws SocketException {
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress() && InetAddressUtils.isIPv4Address(inetAddress.getHostAddress())) {
return inetAddress.getHostAddress().toString();
}
}
}
return null;
}
public String getStatusBarHeight(){
return String.valueOf(UiTool.getStatusBarHeight(context));
}
}
|
||
1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|