Compare commits

...

9 Commits

13 changed files with 329 additions and 111 deletions

View File

@ -3,7 +3,7 @@ plugins {
} }
android { android {
compileSdk 30 compileSdk 28
buildToolsVersion '30.0.3' buildToolsVersion '30.0.3'
defaultConfig { defaultConfig {
@ -11,7 +11,7 @@ android {
minSdk 28 minSdk 28
targetSdk 28 targetSdk 28
versionCode 1 versionCode 1
versionName "1.15" versionName "2.4"
// 1.0 IDATA广播模式处理 // 1.0 IDATA广播模式处理
// 1.1 霍尼韦尔的监听修改扫描网站二维码跳出程序监听失效调整、斑马PDA广播模式设置 // 1.1 霍尼韦尔的监听修改扫描网站二维码跳出程序监听失效调整、斑马PDA广播模式设置
@ -29,6 +29,14 @@ android {
// 1.13 新大陆pda 兼容广播模式NLS-NFT10 // 1.13 新大陆pda 兼容广播模式NLS-NFT10
// 1.14 瑞芯 rk3566_r 添加引用 librockchip.so 新加一个方法返回当前PDA的厂家和型号 // 1.14 瑞芯 rk3566_r 添加引用 librockchip.so 新加一个方法返回当前PDA的厂家和型号
// 1.15 系统状态栏根据配置进行设置 // 1.15 系统状态栏根据配置进行设置
// 1.16 idata pda 不设置模式
// 1.17 霍尼韦尔EDA51、EDA50P调用扫描枪的方法在关闭的时候停止调用扫描枪
// 1.18 瑞兴平板,读取扫描结果,使用同步加锁模式
// 1.19 index页面接入初始化数据
// 2.1 注册PDA的信息存储到文件内部采取mac+固定加密串的MD5加密校验
// 2.2 安卓14以上无法获取mac地址修改成获取唯一id作为mac地址
// 2.3 适配IOT_Device:sc55g PDA 广播模式
// 2.4 适配 qualcomm:mc50 PDA 广播模式
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
ndk { ndk {
abiFilters 'armeabi-v7a' abiFilters 'armeabi-v7a'
@ -80,7 +88,7 @@ android {
}*/ }*/
} }
dependencies { dependencies {
compileOnly 'com.symbol:emdk:+' compileOnly 'com.symbol:emdk:9.1.1'
implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1' implementation 'com.google.android.material:material:1.2.1'
implementation 'com.google.code.gson:gson:2.6.2' implementation 'com.google.code.gson:gson:2.6.2'

View File

@ -99,20 +99,6 @@
</style> </style>
<script>
function saveSetting(){
var data=JSON.stringify({
"address":document.getElementById('address').value,
"port":document.getElementById('port').value,
"path":document.getElementById('path').value,
"screen_rotation":document.getElementById('screen_rotation').value,
"hide_bar":document.getElementById('hide_bar').value
});
window.NetworkSettingEngine.saveSetting(data);
window.View.reload();
}
</script>
</head> </head>
@ -148,4 +134,35 @@
</div> </div>
</div> </div>
</body> </body>
<script>
function init() {
var dstr = window.NetworkSettingEngine.getStringSetting();
if (dstr.length > 0) {
var d = JSON.parse(dstr);
document.getElementById('address').value = d.address;
document.getElementById('port').value = d.port;
document.getElementById('path').value = d.path;
document.getElementById('screen_rotation').value = d.screen_rotation;
document.getElementById('hide_bar').value = d.hide_bar;
console.log("d_data_end_=========================");
}
}
init();
function saveSetting(){
var data=JSON.stringify({
"address":document.getElementById('address').value,
"port":document.getElementById('port').value,
"path":document.getElementById('path').value,
"screen_rotation":document.getElementById('screen_rotation').value,
"hide_bar":document.getElementById('hide_bar').value
});
window.NetworkSettingEngine.saveSetting(data);
window.View.reload();
}
</script>
</html> </html>

View File

@ -10,6 +10,8 @@ package chaoran.business;
public enum BrandEnum { public enum BrandEnum {
//枚举名即为valueOf() //枚举名即为valueOf()
QUALCOMM("qualcomm", "qualcomm"),
IOT_DEVICE("新大陆", "iot_device"),
NEW_LAND("新大陆", "newland"), NEW_LAND("新大陆", "newland"),
HISENSE("海信", "hisense"), HISENSE("海信", "hisense"),
UROVO("DT50 Lite", "urovo"), UROVO("DT50 Lite", "urovo"),
@ -44,7 +46,7 @@ public enum BrandEnum {
code = new String(); code = new String();
} }
for (BrandEnum brandEnum : values()) { for (BrandEnum brandEnum : values()) {
if (brandEnum.code.equals(code.toLowerCase())) { if (brandEnum.code.equalsIgnoreCase(code)) {
return brandEnum; return brandEnum;
} }
} }

View File

@ -6,6 +6,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.content.res.AssetManager;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.hardware.Sensor; import android.hardware.Sensor;
@ -16,6 +17,7 @@ import android.media.MediaPlayer;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Vibrator; import android.os.Vibrator;
import android.util.JsonReader;
import android.util.Log; import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@ -32,13 +34,19 @@ import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import chaoran.business.BrandEnum; import chaoran.business.BrandEnum;
import chaoran.business.R; import chaoran.business.R;
import chaoran.business.adapter.*; import chaoran.business.adapter.*;
import chaoran.business.engine.entity.NetworkSetting;
import chaoran.business.engine.impl.NetworkSettingEngine; import chaoran.business.engine.impl.NetworkSettingEngine;
import chaoran.business.engine.SettingEngine; import chaoran.business.engine.SettingEngine;
import chaoran.business.engine.impl.TekVoiceEngine; import chaoran.business.engine.impl.TekVoiceEngine;
@ -62,8 +70,6 @@ public class MainActivity extends AppCompatActivity implements ResultListener{
MyOrientationDetector myOrientationDetector; MyOrientationDetector myOrientationDetector;
private static int latestOrientation = 0; // 添加一个标志位;最后屏幕的方向
private WebView webView; private WebView webView;
private Adapter adapter; private Adapter adapter;
private VoiceEngine voiceEngine; private VoiceEngine voiceEngine;
@ -86,6 +92,25 @@ public class MainActivity extends AppCompatActivity implements ResultListener{
} }
public static String readInitFile(Context context) {
StringBuffer init = new StringBuffer();
try {
AssetManager assetManager = context.getAssets();
// 打开文件输入流
InputStream inputStream = assetManager.open("init.json");
// 使用BufferedReader进行逐行读取
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String line;
while ((line = reader.readLine()) != null) {
init.append(line);
}
reader.close();
} catch (IOException e) {
Log.e("AssetError", "Failed to read asset file: init.json", e);
}
return init.toString();
}
private void initData() { private void initData() {
BrandEnum brand = BrandEnum.code(Build.MANUFACTURER); BrandEnum brand = BrandEnum.code(Build.MANUFACTURER);
Toast.makeText(this, Build.MANUFACTURER, Toast.LENGTH_LONG).show(); Toast.makeText(this, Build.MANUFACTURER, Toast.LENGTH_LONG).show();
@ -139,6 +164,12 @@ public class MainActivity extends AppCompatActivity implements ResultListener{
case NEW_LAND: case NEW_LAND:
adapter = new NewlandAdapter(this, this); adapter = new NewlandAdapter(this, this);
break; break;
case IOT_DEVICE:
adapter = new IOT_DeviceAdapter(this, this);
break;
case QUALCOMM:
adapter = new QualcommAdapter(this, this);
break;
} }
if (null != adapter) { if (null != adapter) {
adapter.start(); adapter.start();
@ -305,8 +336,35 @@ public class MainActivity extends AppCompatActivity implements ResultListener{
private String url() { private String url() {
SharedPreferences spf = this.getSharedPreferences("crtech", Context.MODE_PRIVATE); SharedPreferences spf = this.getSharedPreferences("crtech", Context.MODE_PRIVATE);
Integer port = spf.getInt("port", -1); Integer port = spf.getInt("port", -1);
Map<String, Object> map = null;
if (port == -1) { if (port == -1) {
return "file:///android_asset/demo/index.html"; try {
// String init = readInitFile(this);
String init = null;
if (init != null && init.length() > 0) {
Gson gson = new Gson();
map = gson.fromJson(init, new TypeToken<Map<String, Object>>(){}.getType());
// 说明采取了配置并且存在ip才认为是一个合法的json配置
if (map.containsKey("ip") && map.get("ip").toString().length() > 0) {
NetworkSetting initData = new NetworkSetting();
initData.setAddress(map.get("ip").toString());
initData.setPort(Integer.parseInt(map.get("port").toString()));
initData.setPath(map.get("path").toString());
initData.setScreen_rotation(Integer.parseInt(map.getOrDefault("screen_rotation", "3").toString()));
initData.setHide_bar(Integer.parseInt(map.getOrDefault("hide_bar", "3").toString()));
settingEngine.saveSetting(initData);
spf = this.getSharedPreferences("crtech", Context.MODE_PRIVATE);
port = initData.getPort();
}else {
map = null;
}
}
}catch (Exception e) {
Log.e("MainActivity", "get init file error");
}
if (map == null) {
return "file:///android_asset/demo/index.html";
}
} }
String address = spf.getString("address", "").replaceAll(" ", ""); String address = spf.getString("address", "").replaceAll(" ", "");
String path = spf.getString("path", "").replaceAll(" ", ""); String path = spf.getString("path", "").replaceAll(" ", "");
@ -416,13 +474,11 @@ public class MainActivity extends AppCompatActivity implements ResultListener{
if (SCREEN_ROTATION == 1 || SCREEN_ROTATION == 3) { if (SCREEN_ROTATION == 1 || SCREEN_ROTATION == 3) {
if (rotate == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || rotate == ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT) { if (rotate == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || rotate == ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT) {
activity.setRequestedOrientation(rotate); activity.setRequestedOrientation(rotate);
latestOrientation = rotate;
} }
} }
if (SCREEN_ROTATION == 2 || SCREEN_ROTATION == 3) { if (SCREEN_ROTATION == 2 || SCREEN_ROTATION == 3) {
if (rotate == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || rotate == ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE) { if (rotate == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || rotate == ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE) {
activity.setRequestedOrientation(rotate); activity.setRequestedOrientation(rotate);
latestOrientation = rotate;
} }
} }
} }
@ -431,69 +487,6 @@ public class MainActivity extends AppCompatActivity implements ResultListener{
} }
/*class MyOrientationDetector implements SensorEventListener {
private Activity activity;
public MyOrientationDetector(Activity activity) {
this.activity = activity;
Sensor orientationSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
sensorManager.registerListener(this, orientationSensor, SensorManager.SENSOR_DELAY_NORMAL);
}
@Override
public void onSensorChanged(SensorEvent event) {
int angle = ((WindowManager) activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation();
if (latestOrientation == angle) {
return;
}
if (SCREEN_ROTATION == 1) {
if (Surface.ROTATION_0 == angle) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
latestOrientation = angle;
}else if (Surface.ROTATION_180 == angle) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
latestOrientation = angle;
}
return;
}else if (SCREEN_ROTATION == 2) {
if (Surface.ROTATION_90 == angle) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
latestOrientation = angle;
}else if (Surface.ROTATION_270 == angle) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
latestOrientation = angle;
}
return;
}
int tmpAngle = latestOrientation;
latestOrientation = angle;
switch (angle) {
case Surface.ROTATION_0:
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
break;
case Surface.ROTATION_90:
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
break;
case Surface.ROTATION_180:
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
break;
case Surface.ROTATION_270:
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
break;
default:
latestOrientation = tmpAngle;
break;
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
}*/
@SuppressLint("WrongConstant") @SuppressLint("WrongConstant")
@Override @Override
public void onConfigurationChanged(Configuration newConfig) { public void onConfigurationChanged(Configuration newConfig) {

View File

@ -8,6 +8,10 @@ import android.content.IntentFilter;
import chaoran.business.activity.ResultListener; import chaoran.business.activity.ResultListener;
import chaoran.business.strategy.Strategy; import chaoran.business.strategy.Strategy;
/**
* 23-6-13 霍尼韦尔EDA56使用
* 25-1-14 兰陵县人民医院 测试可以使用(唐圆圆)
*/
public class HoneywellEda56Adapter implements Adapter { public class HoneywellEda56Adapter implements Adapter {
private Context context; private Context context;
private ResultListener resultListener; private ResultListener resultListener;

View File

@ -39,7 +39,7 @@ public class IDataAdapter implements Adapter {
public Receiver() { public Receiver() {
scannerInerface = new ScannerInerface(context); scannerInerface = new ScannerInerface(context);
scannerInerface.setOutputMode(1); // scannerInerface.setOutputMode(1);
} }
@Override @Override

View File

@ -0,0 +1,56 @@
package chaoran.business.adapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import chaoran.business.activity.ResultListener;
import chaoran.business.strategy.Strategy;
/**
* 适配 sc55g
*/
public class IOT_DeviceAdapter implements Adapter {
private Context context;
private ResultListener resultListener;
private Strategy strategy;
public IOT_DeviceAdapter(Context context, ResultListener resultListener) {
this.context = context;
this.resultListener = resultListener;
strategy = new Receiver();
}
@Override
public void start() {
strategy.executeStrategy(resultListener);
}
@Override
public void stop() {
strategy.exclusiveStrategy();
}
public class Receiver extends BroadcastReceiver implements Strategy {
@Override
public void onReceive(Context context, Intent intent) {
resultListener.result(intent.getStringExtra("message"));
}
@Override
public void executeStrategy(ResultListener resultListener) {
IntentFilter filter = new IntentFilter();
filter.addAction("com.speedata.showdecodedata");
filter.setPriority(2);
context.registerReceiver(this, filter);
}
@Override
public void exclusiveStrategy() {
context.unregisterReceiver(this);
}
}
}

View File

@ -0,0 +1,56 @@
package chaoran.business.adapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import chaoran.business.activity.ResultListener;
import chaoran.business.strategy.Strategy;
/**
* 适配 mc50
*/
public class QualcommAdapter implements Adapter {
private Context context;
private ResultListener resultListener;
private Strategy strategy;
public QualcommAdapter(Context context, ResultListener resultListener) {
this.context = context;
this.resultListener = resultListener;
strategy = new Receiver();
}
@Override
public void start() {
strategy.executeStrategy(resultListener);
}
@Override
public void stop() {
strategy.exclusiveStrategy();
}
public class Receiver extends BroadcastReceiver implements Strategy {
@Override
public void onReceive(Context context, Intent intent) {
resultListener.result(intent.getStringExtra("data"));
}
@Override
public void executeStrategy(ResultListener resultListener) {
IntentFilter filter = new IntentFilter();
filter.addAction("com.scanner.broadcast");
filter.setPriority(2);
context.registerReceiver(this, filter);
}
@Override
public void exclusiveStrategy() {
context.unregisterReceiver(this);
}
}
}

View File

@ -9,10 +9,6 @@ package chaoran.business.adapter;
import android.content.Context; import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Vibrator;
import chaoran.business.R;
import chaoran.business.activity.ResultListener; import chaoran.business.activity.ResultListener;
import chaoran.business.strategy.Strategy; import chaoran.business.strategy.Strategy;
@ -83,16 +79,21 @@ public class RockChipAdapter implements Adapter {
while (running) { while (running) {
String data = data(); String data = data();
if (!data.equals("")) { if (!data.equals("")) {
barcode[0] = barcode[0] + data; synchronized (RockChipAdapter.class) {
barcode[0] = barcode[0] + data;
}
try { try {
Thread.sleep(20); Thread.sleep(20);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
if (!"".equals(barcode[0])) { synchronized (RockChipAdapter.class) {
resultListener.result(barcode[0]); if (!"".equals(barcode[0])) {
barcode[0] = ""; // Log.i("listen", "Thread result data: \t\t" + barcode[0] + "\t\t" + System.currentTimeMillis());
resultListener.result(barcode[0]);
barcode[0] = "";
}
} }
} }
}).start(); }).start();
@ -105,16 +106,21 @@ public class RockChipAdapter implements Adapter {
} }
private String data() { private String data() {
if (mFileInputStream == null) return ""; if (mFileInputStream == null) {
try { return "";
int size = mFileInputStream.available(); }
byte[] buffer = new byte[size]; synchronized (RockChipAdapter.class) {
size = mFileInputStream.read(buffer); try {
if (size > 0) { int size = mFileInputStream.available();
return new String(buffer); byte[] buffer = new byte[size];
size = mFileInputStream.read(buffer);
if (size > 0) {
String data = new String(buffer);
return data;
}
} catch (IOException e) {
e.printStackTrace();
} }
} catch (IOException e) {
e.printStackTrace();
} }
return ""; return "";
} }

View File

@ -45,6 +45,7 @@ public class NetworkSettingEngine implements SettingEngine {
networkSetting.setPort(port); networkSetting.setPort(port);
networkSetting.setPath(path); networkSetting.setPath(path);
networkSetting.setScreen_rotation(screen_rotation); networkSetting.setScreen_rotation(screen_rotation);
networkSetting.setHide_bar(spf.getInt("hide_bar", 3));
return networkSetting; return networkSetting;
} }

View File

@ -57,7 +57,8 @@ public class ScanServiceEDA50P extends Service
super.onCreate(); super.onCreate();
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel channel = null; NotificationChannel channel = null;
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { //适配9.0service if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { //适配9.0service
// if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { //适配9.0service
channel = new NotificationChannel(notificationId, notificationName, NotificationManager.IMPORTANCE_HIGH); channel = new NotificationChannel(notificationId, notificationName, NotificationManager.IMPORTANCE_HIGH);
notificationManager.createNotificationChannel(channel); notificationManager.createNotificationChannel(channel);
Notification notification = new Notification.Builder(getApplicationContext(), notificationId).build(); Notification notification = new Notification.Builder(getApplicationContext(), notificationId).build();
@ -78,9 +79,11 @@ public class ScanServiceEDA50P extends Service
//Service被关闭之前回调 //Service被关闭之前回调
@Override @Override
public void onDestroy() { public void onDestroy() {
Log.i(TAG, "onDestory方法被调用!"); Log.i(TAG, "onDestroy方法被调用!");
super.onDestroy(); super.onDestroy();
if (mBarcodeReader != null) {
mBarcodeReader.release();
}
if (this.mInternalScannerReader != null) { if (this.mInternalScannerReader != null) {
this.mInternalScannerReader.removeBarcodeListener(this); this.mInternalScannerReader.removeBarcodeListener(this);
this.mInternalScannerReader.removeTriggerListener(this); this.mInternalScannerReader.removeTriggerListener(this);

View File

@ -1,11 +1,16 @@
package chaoran.business.utils; package chaoran.business.utils;
import static androidx.core.content.ContextCompat.getSystemService;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.bluetooth.le.ScanSettings;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build; import android.os.Build;
import android.provider.Settings;
import android.util.Log; import android.util.Log;
import android.view.Surface; import android.view.Surface;
import android.view.View; import android.view.View;
@ -18,13 +23,12 @@ import java.net.NetworkInterface;
import java.net.SocketException; import java.net.SocketException;
import java.util.Enumeration; import java.util.Enumeration;
import chaoran.business.BrandEnum;
import chaoran.business.BuildConfig; import chaoran.business.BuildConfig;
import chaoran.business.R;
import chaoran.business.activity.MainActivity;
public class LocalAddressUtil { public class LocalAddressUtil {
public final static String SSO_KEY = "!~CROP@CRTECH@PDA~!";
private Context context; private Context context;
private Activity activity; private Activity activity;
@ -63,6 +67,14 @@ public class LocalAddressUtil {
@SuppressLint("JavascriptInterface") @SuppressLint("JavascriptInterface")
@JavascriptInterface @JavascriptInterface
public String getMacAddress(){//可以兼容安卓7以下 public String getMacAddress(){//可以兼容安卓7以下
if (Build.VERSION.SDK_INT >= 34) { // Android 14 is code-named Tiramisu
try {
return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
}catch (Exception e) {
e.printStackTrace();
return "02:00:00:00:00:02";
}
}
String macAddress = null; String macAddress = null;
StringBuffer buf = new StringBuffer(); StringBuffer buf = new StringBuffer();
NetworkInterface networkInterface = null; NetworkInterface networkInterface = null;
@ -160,6 +172,32 @@ public class LocalAddressUtil {
} }
} }
@SuppressLint("JavascriptInterface")
@JavascriptInterface
public String registerMac(String applyMac) {
try {
String mac = this.getMacAddress();
String md5Hash = MD5.md5(mac + SSO_KEY);
if (md5Hash != null && md5Hash.equals(applyMac)) {
// 将允许注册适配的mac写入文件中
SharedPreferences.Editor editor = context.getSharedPreferences("CrtechPdaConfig", Context.MODE_PRIVATE).edit();
editor.putString("checkMac", "success");
editor.commit();
return "success";
}
}catch (Exception ignored) {
}
return "error";
}
@SuppressLint("JavascriptInterface")
@JavascriptInterface
public String checkMacRegister() {
SharedPreferences sharedPreferences = context.getSharedPreferences("CrtechPdaConfig", Context.MODE_PRIVATE);
return sharedPreferences.getString("checkMac", "error");
}
@SuppressLint("JavascriptInterface") @SuppressLint("JavascriptInterface")
@JavascriptInterface @JavascriptInterface
public String getApkVersion() { public String getApkVersion() {

View File

@ -0,0 +1,34 @@
package chaoran.business.utils;
import java.security.MessageDigest;
// 从框架的MD5加密类拷贝过来的
public class MD5 {
private static final String key = "aa";
private static final char[] hexDigits = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
public static final String md5(String s) {
return s == null ? null : md5(s.getBytes());
}
public static final String md5(byte[] bytes) {
try {
MessageDigest mdTemp = MessageDigest.getInstance("MD5");
mdTemp.update(bytes);
byte[] md = mdTemp.digest();
int j = md.length;
char[] str = new char[j * 2];
int k = 0;
for(int i = 0; i < j; ++i) {
byte byte0 = md[i];
str[k++] = hexDigits[byte0 >>> 4 & 15];
str[k++] = hexDigits[byte0 & 15];
}
return new String(str);
} catch (Exception var8) {
return null;
}
}
}