Class AppUsageUploader
-
- All Implemented Interfaces:
@Deprecated() public final class AppUsageUploaderThis class is used for uploading client usage information to mobile services.
Preparation-- Before using AppUsageUploader
- Need to enable the server to upload application-specific usage statistics and reports from mobile devices. See Defining Usage Report Policy.
- A connection to mobile services has been established using
okHttpClient. AppUsage.initialize(Context, SettingsParameters, char[])has been called.
Implementing UploadListener: Optional but recommended. For example,
class MyUsageUploadListener implements UploadListener { public void onSuccess() { sLogger.debug("Upload completed successfully"); } public void onError(Throwable error) { if (error instanceof HttpException) { sLogger.debug("Upload with server error: {}, code = {}", ((HttpException) error).message(), ((HttpException) error).code()); } else { sLogger.debug("Upload error: {}", error.getMessage()); } } public void onProgress(int percentUploaded) { // For example, update the progress bar... } }Registering a UploadListener:
MyUsageUploadListener listener = new MyUsageUploadListener; // Call addUsageUploadListener(listener) AppUsageUploader.addUsageUploadListener(listener);Uploading-- via upload.
AppUsageUploaderruns in anAsyncTask, it retrieves the snapshot from the usage store, converts the usage records to the format required by SAP Mobile Services, then uploads them to the server.onProgress is invoked multiple times during usage uploading, onSuccess is invoked after the upload is completed successfully, and onError is invoked when upload failed or cancelled.
// Establishes a connection to mobile services using okHttpClient. .... AppUsageUploader.upload(okHttpClient, targetID);Viewing Usage Reports on Server-- After successful client data upload, you can find your reports on the server.
See Viewing Client Usage Reports. Deprecated since version 4.0, please use uploadUsageData
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classAppUsageUploader.UploadWorkerpublic interfaceAppUsageUploader.UploadListenerListener for the
AppUsageUploaderto dispatch usage upload events-- progress and completion status.
-
Method Summary
Modifier and Type Method Description static voidcancelUpload()Cancels upload for the system default target ID if an upload is in progress. static voidupload()Uploads the usage records associated with the system default target ID to the CPMS server asynchronously using AsyncTaskinternally.static voidupload(@NonNull() OkHttpClient httpClient)Uploads the usage records associated with the system default target ID to the CPMS server asynchronously using AsyncTaskinternally.static voidupload(@NonNull() String targetId)Uploads the usage records associated with the specified target ID to the CPMS server asynchronously using AsyncTaskinternally.static voidupload(@NonNull() OkHttpClient httpClient, @NonNull() String targetId)Uploads the usage records associated with the specified target ID to the CPMS server asynchronously using AsyncTaskinternally.static voidsetListener(@Nullable() AppUsageUploader.UploadListener listener)static voidaddUploadListener(@NonNull() AppUsageUploader.UploadListener listener)Register a listener for usage upload events. static voidremoveUploadListener(@NonNull() AppUsageUploader.UploadListener listener)Unregister a listener for usage upload events. -
-
Method Detail
-
cancelUpload
static void cancelUpload()
Cancels upload for the system default target ID if an upload is in progress.
-
upload
static void upload()
Uploads the usage records associated with the system default target ID to the CPMS server asynchronously using
AsyncTaskinternally.Note: This method must be called in the UI(main) thread. If the caller has set up UploadListener, its callback methods will be invoked in UI thread.
Preconditions:
1.
AppUsage.initialize(Context, SettingsParameters, char[])has been called already.2. com.sap.cloud.mobile.foundation.usage.AppUsageRecords have been reported and persisted using methods provided by AppUsage.
3. addUploadListener has been called.
Steps:
1. Takes a snapshot to collect usage records associated with the given target ID reported so far.
2. Converts the snapshot to the JSON format required by mobile services.
3. Uploads the formatted data to the specified SAP server URL.
4. Removes the uploaded records from the secure usage store upon successful upload.
-
upload
static void upload(@NonNull() OkHttpClient httpClient)
Uploads the usage records associated with the system default target ID to the CPMS server asynchronously using
AsyncTaskinternally.Note: This method must be called in the UI(main) thread. If the caller has set up UploadListener, its callback methods will be invoked in UI thread.
Preconditions:
1.
AppUsage.initialize(Context, SettingsParameters, char[])has been called already.2. com.sap.cloud.mobile.foundation.usage.AppUsageRecords have been reported and persisted using methods provided by AppUsage.
3. addUploadListener has been called.
Steps:
1. Takes a snapshot to collect usage records associated with the given target ID reported so far.
2. Converts the snapshot to the JSON format required by mobile services.
3. Uploads the formatted data to the specified SAP server URL.
4. Removes the uploaded records from the secure usage store upon successful upload.
- Parameters:
httpClient- AnOkHttpClientthat has the mobile services session already established
-
upload
static void upload(@NonNull() String targetId)
Uploads the usage records associated with the specified target ID to the CPMS server asynchronously using
AsyncTaskinternally.Note: This method must be called in the UI(main) thread. If the caller has set up UploadListener, its callback methods will be invoked in UI thread.
Preconditions:
1.
AppUsage.initialize(Context, SettingsParameters, char[])has been called already.2. com.sap.cloud.mobile.foundation.usage.AppUsageRecords have been reported and persisted using methods provided by AppUsage.
3. addUploadListener has been called.
Steps:
1. Takes a snapshot to collect usage records associated with the given target ID reported so far.
2. Converts the snapshot to the JSON format required by mobile services.
3. Uploads the formatted data to the specified SAP server URL.
4. Removes the uploaded records from the secure usage store upon successful upload.
- Parameters:
targetId- the targetID to create the snapshot
-
upload
static void upload(@NonNull() OkHttpClient httpClient, @NonNull() String targetId)
Uploads the usage records associated with the specified target ID to the CPMS server asynchronously using
AsyncTaskinternally.Note: This method must be called in the UI(main) thread. If the caller has set up UploadListener, its callback methods will be invoked in UI thread.
Preconditions:
1.
AppUsage.initialize(Context, SettingsParameters, char[])has been called already.2. com.sap.cloud.mobile.foundation.usage.AppUsageRecords have been reported and persisted using methods provided by AppUsage.
3. addUploadListener has been called.
Steps:
1. Takes a snapshot to collect usage records associated with the given target ID reported so far.
2. Converts the snapshot to the JSON format required by mobile services.
3. Uploads the formatted data to the specified SAP server URL.
4. Removes the uploaded records from the secure usage store upon successful upload.
- Parameters:
httpClient- AnOkHttpClientthat has the mobile services session already establishedtargetId- the targetID to create the snapshot
-
setListener
@Deprecated() static void setListener(@Nullable() AppUsageUploader.UploadListener listener)
- Parameters:
listener- a listener for usage report upload events ornullto unregister the listener
-
addUploadListener
static void addUploadListener(@NonNull() AppUsageUploader.UploadListener listener)
Register a listener for usage upload events. Events will be triggered on the main thread.
- Parameters:
listener- a listener for usage upload events.
-
removeUploadListener
static void removeUploadListener(@NonNull() AppUsageUploader.UploadListener listener)
Unregister a listener for usage upload events.
- Parameters:
listener- the listener to unregister.
-
-
-
-