<Button
android:id="@+id/b_offlineSync"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="performSync"
android:enabled="false"
android:text="Sync" />
public void performSync(View v) {
toastAMessage("Performing offline store sync.");
Log.d(myTag, "Performing offline store sync.");
Log.d(myTag, "Beginning offline store upload.");
myOfflineDataProvider.upload(() -> {
toastAMessage("Completed upload, beginning download.");
Log.d(myTag, "Completed upload, beginning download.");
myOfflineDataProvider.download(() -> {
toastAMessage("Completed download, sync complete.");
Log.d(myTag, "Completed download, sync complete.");
}, e -> {
toastAMessage("Failed to download the offline store, sync failed with error: " + e.toString());
Log.d(myTag, "Failed to download the offline store, sync failed with error: " + e.toString());
});
}, e -> {
toastAMessage("Failed to upload the offline store, sync failed with error: " + e.toString());
Log.d(myTag, "Failed to upload the offline store, sync failed with error: " + e.toString());
});
}
findViewById(R.id.b_offlineSync).setEnabled(true);
OfflineODataDelegate delegate = new OfflineODataDelegate() {
@Override
public void updateDownloadProgress(OfflineODataProvider provider, OfflineODataProgress progress) {
super.updateDownloadProgress(provider, progress);
runOnUiThread(new Runnable() {
@Override
public void run() {
// As an example, log the # of bytes received
Log.d(myTag, "Download Bytes Received: " + progress.getBytesReceived());
}
});
}
@Override
public void updateFileDownloadProgress(OfflineODataProvider provider, OfflineODataFileDownloadProgress progress) {
super.updateFileDownloadProgress(provider, progress);
runOnUiThread(new Runnable() {
@Override
public void run() {
// As an example, log the # of bytes received
Log.d(myTag, "Update File Download Bytes Received: " + progress.getBytesReceived());
}
});
}
};
myOfflineDataProvider = new OfflineODataProvider(url, offParam, myOkHttpClient, null, delegate);
ErrorArchive
. The ErrorArchive
is used to collect errors caused when using OData. The app can show the user the conflicts and let the user decide how to handle each error. For more information on error handling, see the SAP Handling Errors and Conflicts documentation, as well as the page on Handling Failed Requests. The ErrorArchive
is a list of entities that have the properties listed in the ErrorArchive Entity Properties list.
// Get ErrorArchive entity set
EntitySet errorArchiveSet = myOfflineServiceContainer.getEntitySet("ErrorArchive");
EntityType errorArchiveType = errorArchiveSet.getEntityType();
Property affectedEntityNavProp = errorArchiveType.getProperty("AffectedEntity");
Property requestIDProp = errorArchiveType.getProperty("RequestID");
// more properties such as RequestBody, RequestMethod, RequestURL, Message
// CustomTag, Domain, HTTpStatusCode, Code, and InnerError
DataQuery query = new DataQuery().from(errorArchiveSet).orderBy(requestIDProp);
EntityValueList errorEntities = myOfflineServiceContainer.executeQuery(query).getEntityList();
// Iterate through the entities that have errors
for (EntityValue errorEntity : errorEntities) {
myOfflineServiceContainer.loadProperty(affectedEntityNavProp, errorEntity);
EntityValue affectedEntity = affectedEntityNavProp.getEntity(errorEntity);
// Process each affected entity
// For this example application, we just log the entity
Log.d(myTag,"Error found: " + affectedEntity.toString());
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
24 | |
11 | |
8 | |
7 | |
7 | |
7 | |
6 | |
6 | |
6 | |
6 |