正式讯飞语音环境
This commit is contained in:
101
app/src/main/java/chaoran/business/utils/LocalAddressUtil.java
Normal file
101
app/src/main/java/chaoran/business/utils/LocalAddressUtil.java
Normal file
@ -0,0 +1,101 @@
|
||||
package chaoran.business.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.bluetooth.le.ScanSettings;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
import android.webkit.JavascriptInterface;
|
||||
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.util.Enumeration;
|
||||
|
||||
public class LocalAddressUtil {
|
||||
@SuppressLint("JavascriptInterface")
|
||||
@JavascriptInterface
|
||||
public String getIpAddress() {
|
||||
try {
|
||||
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
|
||||
NetworkInterface intf = en.nextElement();
|
||||
// if(!intf.getDisplayName().equals("eth0")) continue;
|
||||
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
|
||||
InetAddress inetAddress = enumIpAddr.nextElement();
|
||||
if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) {
|
||||
return inetAddress.getHostAddress();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SocketException ex) {
|
||||
Log.e("address: local", ex.toString());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressLint("JavascriptInterface")
|
||||
@JavascriptInterface
|
||||
public String getMacAddress(){//可以兼容安卓7以下
|
||||
String macAddress = null;
|
||||
StringBuffer buf = new StringBuffer();
|
||||
NetworkInterface networkInterface = null;
|
||||
try {
|
||||
networkInterface = NetworkInterface.getByName("eth1");
|
||||
if (networkInterface == null) {
|
||||
networkInterface = NetworkInterface.getByName("wlan0");
|
||||
}
|
||||
if (networkInterface == null) {
|
||||
return "02:00:00:00:00:02";
|
||||
}
|
||||
byte[] addr = networkInterface.getHardwareAddress();
|
||||
for (byte b : addr) {
|
||||
buf.append(String.format("%02X:", b));
|
||||
}
|
||||
if (buf.length() > 0) {
|
||||
buf.deleteCharAt(buf.length() - 1);
|
||||
}
|
||||
macAddress = buf.toString();
|
||||
} catch (SocketException e) {
|
||||
e.printStackTrace();
|
||||
return "02:00:00:00:00:02";
|
||||
}
|
||||
return macAddress;
|
||||
}
|
||||
@SuppressLint("JavascriptInterface")
|
||||
@JavascriptInterface
|
||||
public String getInfo(int type){
|
||||
String info;
|
||||
switch (type) {
|
||||
case 1: info = Build.BRAND;break;//品牌
|
||||
case 2: info = Build.MODEL;break;//型号
|
||||
case 3: info = Build.MANUFACTURER;break;//厂商
|
||||
case 4: info = Build.DEVICE;break;//设备名
|
||||
case 5: info = Build.ID;break;//设备硬件id
|
||||
// case 6: info = Build.SERIAL;break;//序列号,可能获取不到
|
||||
default: info = "";break;
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
public void test(){
|
||||
Log.e("test", "MANUFACTURER=" + Build.MANUFACTURER);
|
||||
Log.e("test", "BRAND=" + Build.BRAND);
|
||||
Log.e("test", "MODEL=" + Build.MODEL);
|
||||
Log.e("test", "VERSION.RELEASE=" + Build.VERSION.RELEASE);
|
||||
Log.e("test", "VERSION.SDK_INT=" + Build.VERSION.SDK_INT);
|
||||
Log.e("test", "DEVICE=" + Build.DEVICE);
|
||||
Log.e("test", "HOST=" + Build.HOST);
|
||||
Log.e("test", "ID=" + Build.ID);
|
||||
Log.e("test", "TIME=" + Build.TIME);
|
||||
Log.e("test", "TYPE=" + Build.TYPE);
|
||||
Log.e("test", "PRODUCT=" + Build.PRODUCT);
|
||||
Log.e("test", "BOARD=" + Build.BOARD);
|
||||
Log.e("test", "DISPLAY=" + Build.DISPLAY);
|
||||
Log.e("test", "FINGERPRINT=" + Build.FINGERPRINT);
|
||||
Log.e("test", "HARDWARE=" + Build.HARDWARE);
|
||||
Log.e("test", "BOOTLOADER=" + Build.BOOTLOADER);
|
||||
Log.e("test", "TAGS=" + Build.TAGS);
|
||||
Log.e("test", "UNKNOWN=" + Build.UNKNOWN);
|
||||
Log.e("test", "USER=" + Build.USER);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user