fix(app): 优化读卡流程并处理异常情况
- 修改 TAG 名称为 ReadCardActivity - 增加对 mBluetoothController 的空检查 - 在连接蓝牙设备前添加延迟 - 修改 finish() 为 mBluetoothController.stopTrade() 以正确结束交易 - 在 onStopTradeSuccess() 中添加 finish() 以关闭活动
This commit is contained in:
Generated
-1
@@ -1,4 +1,3 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK">
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
* @author JoeAllen
|
* @author JoeAllen
|
||||||
*/
|
*/
|
||||||
public class ReadCardActivity extends AppCompatActivity {
|
public class ReadCardActivity extends AppCompatActivity {
|
||||||
private static final String TAG = "MainActivity";
|
private static final String TAG = "ReadCardActivity";
|
||||||
public String errMsg, readerErrMsg, mac, tusn, appVersion, kernelVersion, tradeData, money = "1", countryCode = "0702", currencyCode = "0702", cardNum;
|
public String errMsg, readerErrMsg, mac, tusn, appVersion, kernelVersion, tradeData, money = "1", countryCode = "0702", currencyCode = "0702", cardNum;
|
||||||
Handler handler = new Handler(Looper.getMainLooper());
|
Handler handler = new Handler(Looper.getMainLooper());
|
||||||
private BluetoothAdapter mBluetoothAdapter;
|
private BluetoothAdapter mBluetoothAdapter;
|
||||||
@@ -80,6 +80,9 @@ public class ReadCardActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
|
|
||||||
Log.d(TAG, "tradeDataStr: " + tradeDataStr);
|
Log.d(TAG, "tradeDataStr: " + tradeDataStr);
|
||||||
|
if(mBluetoothController==null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
mBluetoothController.startEmvProcess(50, Util.HexToBin(tradeDataStr.toString()));
|
mBluetoothController.startEmvProcess(50, Util.HexToBin(tradeDataStr.toString()));
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -106,7 +109,7 @@ public class ReadCardActivity extends AppCompatActivity {
|
|||||||
mBluetoothLeService = ((BluetoothLeService.LocalBinder) service).getService();
|
mBluetoothLeService = ((BluetoothLeService.LocalBinder) service).getService();
|
||||||
if (!mBluetoothLeService.initialize()) {
|
if (!mBluetoothLeService.initialize()) {
|
||||||
Log.e(TAG, "无法初始化蓝牙");
|
Log.e(TAG, "无法初始化蓝牙");
|
||||||
finish();
|
mBluetoothController.stopTrade();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,6 +119,11 @@ public class ReadCardActivity extends AppCompatActivity {
|
|||||||
public void connected() {
|
public void connected() {
|
||||||
isConnected = true;
|
isConnected = true;
|
||||||
Log.d(TAG, "connected1==========");
|
Log.d(TAG, "connected1==========");
|
||||||
|
try {
|
||||||
|
Thread.sleep(200);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
beginReadCard();
|
beginReadCard();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +149,7 @@ public class ReadCardActivity extends AppCompatActivity {
|
|||||||
mBluetoothController.connectDevice(mac);
|
mBluetoothController.connectDevice(mac);
|
||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "初始化 mBluetoothController 失败");
|
Log.e(TAG, "初始化 mBluetoothController 失败");
|
||||||
finish();
|
mBluetoothController.stopTrade();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,7 +207,10 @@ public class ReadCardActivity extends AppCompatActivity {
|
|||||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
||||||
return insets;
|
return insets;
|
||||||
});
|
});
|
||||||
findViewById(R.id.test).setOnClickListener(v -> finish());
|
findViewById(R.id.test).setOnClickListener(v -> {
|
||||||
|
|
||||||
|
mBluetoothController.stopTrade();
|
||||||
|
});
|
||||||
|
|
||||||
final BluetoothManager bluetoothManager =
|
final BluetoothManager bluetoothManager =
|
||||||
(BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
|
(BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
|
||||||
@@ -586,6 +597,7 @@ public class ReadCardActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onStopTradeSuccess() {
|
public void onStopTradeSuccess() {
|
||||||
Log.e(TAG, "onStopTradeSuccess");
|
Log.e(TAG, "onStopTradeSuccess");
|
||||||
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -622,6 +634,7 @@ public class ReadCardActivity extends AppCompatActivity {
|
|||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
try {
|
try {
|
||||||
handler.removeCallbacks(readRunnable);
|
handler.removeCallbacks(readRunnable);
|
||||||
|
|
||||||
unbindService(mServiceConnection);
|
unbindService(mServiceConnection);
|
||||||
if (mBluetoothLeService != null) {
|
if (mBluetoothLeService != null) {
|
||||||
mBluetoothLeService.disconnect();
|
mBluetoothLeService.disconnect();
|
||||||
|
|||||||
Reference in New Issue
Block a user