Skip to content

Commit 497c6fc

Browse files
committed
Merge branch 'task/generic_qrcode_handling' into 'master'
Invalid QR code handling See merge request idf/esp-idf-provisioning-android!56
2 parents 0e54de2 + 3e04d02 commit 497c6fc

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

app/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ android {
1818
minSdkVersion 23
1919
targetSdkVersion 30
2020
versionCode 14
21-
versionName "2.0.11 - ${getGitHash()}"
21+
versionName "2.0.12 - ${getGitHash()}"
2222
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
2323
}
2424

app/src/main/java/com/espressif/ui/activities/AddDeviceActivity.java

+19
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,25 @@ public void run() {
436436
}
437437
});
438438
}
439+
440+
@Override
441+
public void onFailure(Exception e, String qrCodeData) {
442+
// Called when QR code is not in supported format.
443+
// Comment below error handling and do whatever you want to do with your QR code data.
444+
Log.e(TAG, "Error : " + e.getMessage());
445+
Log.e(TAG, "QR code data : " + qrCodeData);
446+
447+
runOnUiThread(new Runnable() {
448+
449+
@Override
450+
public void run() {
451+
hideLoading();
452+
String msg = e.getMessage();
453+
Toast.makeText(AddDeviceActivity.this, msg, Toast.LENGTH_LONG).show();
454+
finish();
455+
}
456+
});
457+
}
439458
};
440459

441460
private void goToWiFiScanActivity() {

provisioning/src/main/java/com/espressif/provisioning/ESPProvisionManager.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ public void run() {
301301
}
302302
} else {
303303
Log.e(TAG, "Transport is not available in QR code data");
304-
qrCodeScanListener.onFailure(new RuntimeException("QR code is not valid"));
304+
qrCodeScanListener.onFailure(new RuntimeException("QR code is not valid"), scannedData);
305305
return;
306306
}
307307

@@ -329,10 +329,10 @@ public void run() {
329329
} catch (JSONException e) {
330330

331331
e.printStackTrace();
332-
qrCodeScanListener.onFailure(new RuntimeException("QR code is not valid"));
332+
qrCodeScanListener.onFailure(new RuntimeException("QR code is not valid"), scannedData);
333333
}
334334
} else {
335-
qrCodeScanListener.onFailure(new RuntimeException("QR code is not valid"));
335+
qrCodeScanListener.onFailure(new RuntimeException("QR code is not valid"), scannedData);
336336
}
337337
}
338338
});

provisioning/src/main/java/com/espressif/provisioning/listeners/QRCodeScanListener.java

+8
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,12 @@ public interface QRCodeScanListener {
3939
* @param e Exception
4040
*/
4141
void onFailure(Exception e);
42+
43+
/**
44+
* Called when QR code data has different format.
45+
*
46+
* @param e Exception
47+
* @param data QR code data string.
48+
*/
49+
void onFailure(Exception e, String data);
4250
}

0 commit comments

Comments
 (0)