Add the uploadLog
method below to the bottom of the MainActivity
class.
public void uploadLog() {
LOGGER.debug("In uploadLog");
myLogUploadListener = new Logging.UploadListener() {
@Override
public void onSuccess() {
LOGGER.debug("Log upload completed");
Toast.makeText(getApplicationContext(), "Log upload completed and was successful!",
Toast.LENGTH_LONG).show();
Logging.removeLogUploadListener(myLogUploadListener);
}
@Override
public void onError(@NonNull Throwable throwable) {
LOGGER.debug("Log upload encountered an error with message: " + throwable.getMessage());
Toast.makeText(getApplicationContext(), "Log upload failed with error message: " + throwable.getMessage(),
Toast.LENGTH_LONG).show();
Logging.removeLogUploadListener(myLogUploadListener);
}
@Override
public void onProgress(int percentUploaded) {
LOGGER.debug("Log upload progress: " + percentUploaded);
}
};
Logging.addLogUploadListener(myLogUploadListener);
// String serviceURL = flowContext.getOnboardingParameters().getSettingsParameters().getBackendUrl();
// String deviceID = flowContext.getOnboardingParameters().getSettingsParameters().getDeviceId();
OkHttpClient okHttpClient = flowContext.getOkHttpClient();
SettingsParameters sp = flowContext.getOnboardingParameters().getSettingsParameters();
Logging.uploadLog(okHttpClient, sp, Logging.UploadType.MERGE);
}
The above method uploads the existing log to Mobile Services and displays the result of the action. Notice that the Logging.uploadLog
method requires an OkHttpClient
and SettingsParameters
variables that are retrieved from the flowContext
.
Add the following line to the onUploadLog
method.
uploadLog();