fix(app): 优化读卡流程并处理异常情况
- 修改 TAG 名称为 ReadCardActivity - 增加对 mBluetoothController 的空检查 - 在连接蓝牙设备前添加延迟 - 修改 finish() 为 mBluetoothController.stopTrade() 以正确结束交易 - 在 onStopTradeSuccess() 中添加 finish() 以关闭活动
This commit is contained in:
@@ -44,7 +44,7 @@ import java.util.concurrent.TimeUnit;
|
||||
* @author JoeAllen
|
||||
*/
|
||||
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;
|
||||
Handler handler = new Handler(Looper.getMainLooper());
|
||||
private BluetoothAdapter mBluetoothAdapter;
|
||||
@@ -80,6 +80,9 @@ public class ReadCardActivity extends AppCompatActivity {
|
||||
|
||||
|
||||
Log.d(TAG, "tradeDataStr: " + tradeDataStr);
|
||||
if(mBluetoothController==null){
|
||||
return;
|
||||
}
|
||||
mBluetoothController.startEmvProcess(50, Util.HexToBin(tradeDataStr.toString()));
|
||||
|
||||
} catch (Exception e) {
|
||||
@@ -106,7 +109,7 @@ public class ReadCardActivity extends AppCompatActivity {
|
||||
mBluetoothLeService = ((BluetoothLeService.LocalBinder) service).getService();
|
||||
if (!mBluetoothLeService.initialize()) {
|
||||
Log.e(TAG, "无法初始化蓝牙");
|
||||
finish();
|
||||
mBluetoothController.stopTrade();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -116,6 +119,11 @@ public class ReadCardActivity extends AppCompatActivity {
|
||||
public void connected() {
|
||||
isConnected = true;
|
||||
Log.d(TAG, "connected1==========");
|
||||
try {
|
||||
Thread.sleep(200);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
beginReadCard();
|
||||
}
|
||||
|
||||
@@ -141,7 +149,7 @@ public class ReadCardActivity extends AppCompatActivity {
|
||||
mBluetoothController.connectDevice(mac);
|
||||
} else {
|
||||
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);
|
||||
return insets;
|
||||
});
|
||||
findViewById(R.id.test).setOnClickListener(v -> finish());
|
||||
findViewById(R.id.test).setOnClickListener(v -> {
|
||||
|
||||
mBluetoothController.stopTrade();
|
||||
});
|
||||
|
||||
final BluetoothManager bluetoothManager =
|
||||
(BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
|
||||
@@ -586,6 +597,7 @@ public class ReadCardActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void onStopTradeSuccess() {
|
||||
Log.e(TAG, "onStopTradeSuccess");
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -622,6 +634,7 @@ public class ReadCardActivity extends AppCompatActivity {
|
||||
super.onDestroy();
|
||||
try {
|
||||
handler.removeCallbacks(readRunnable);
|
||||
|
||||
unbindService(mServiceConnection);
|
||||
if (mBluetoothLeService != null) {
|
||||
mBluetoothLeService.disconnect();
|
||||
|
||||
Reference in New Issue
Block a user