Overview
This Tutorial provides a walk-through of the steps to update firmware
Create The Project
- Start by creating a new project in Android Studio. For help, see the Android Studio tutorial.
- Refer Hello RFID to prepare basic setup to work with RFID Reader and then follow this guide
Details
SDK can update the TC53E and EM45 firmware using the following API.
updateFirmware(String path, String ip)
User needs to make sure that path is obtained using the Android Storage Access Framework. IP address of the interface from where reader reach your android device hosting the firmware files.
Setting Permission
The code is used to request the MANAGE_EXTERNAL_STORAGE permission, allowing the app to access and manage all files on the device's external storage. This is part of the MANAGE_EXTERNAL_STORAGE permission introduced in Android 11 above.
if(!Environment.isExternalStorageManager()){
try{
Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
intent.addCategory("android.intent.category.DEFAULT");
intent.setData(Uri.parse(String.format("package:%s",getApplicationContext().getPackageName())));
startActivityIfNeeded(intent,101);
} catch (Exception exception){
Intent intent = new Intent();
intent.setAction(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
startActivityIfNeeded(intent,101);
}
}
Setting in the manifest file for accessing the firmware file from the external storage.
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
Performing Operation
Calling the Firmware update API call
try {
String path ="/storage/emulated/0/Download/CAAHFS00-001-R01D0.DAT";
String ip = "127.0.0.1"; // localHost IP
reader.Config.updateFirmware(path, ip);
} catch (InvalidUsageException | OperationFailureException e) {
if (e.getStackTrace().length > 0) {
Log.e(TAG, e.getStackTrace()[0].toString());
}
}
Getting firmware update status under event status notification
public void eventStatusNotify(RfidStatusEvents rfidStatusEvents) {
if(rfidStatusEvents.StatusEventData.getStatusEventType() == STATUS_EVENT_TYPE.FIRMWARE_UPDATE_EVENT){
String status = rfidStatusEvents.StatusEventData.FWEventData.getStatus();
int imageDownloadProgress = rfidStatusEvents.StatusEventData.FWEventData.getImageDownloadProgress();
int overallUpdateProgress = rfidStatusEvents.StatusEventData.FWEventData.getOverallUpdateProgress();
Log.d(TAG,"FW status: "+status+", idp: "+imageDownloadProgress+", ovp: "+overallUpdateProgress );
}
}
}
Closer Look
Support function to launch file storage and select the firmware file.
NOTE : Don't select file from shortcut path.
public void openFileStorage() {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
Uri uri = Uri.parse("content://com.android.externalstorage.documents/document/primary:Download");
intent.putExtra("DocumentsContract.EXTRA_INITIAL_URI", uri);
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
activityResultLauncher.launch(intent);
}
public static File selectedPlugIn = null;
ActivityResultLauncher activityResultLauncher = registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
new ActivityResultCallback() {
@Override
public void onActivityResult(ActivityResult result) {
if (result.getResultCode() == Activity.RESULT_OK) {
Intent data = result.getData();
Uri documentUri;
if (data != null) {
documentUri = data.getData();
selectedPlugIn = new File(documentUri.getPath());
selectedPlugIn = new File(selectedPlugIn.toString().replace("/document/primary:","/storage/emulated/0/"));
}
}
}
});