com.amazonaws.mobileconnectors.cognito
Class CognitoSyncManager

java.lang.Object
  extended by com.amazonaws.mobileconnectors.cognito.CognitoSyncManager

public class CognitoSyncManager
extends java.lang.Object

This saves Dataset in SQLite database. Here is a sample usage:

 CognitoCachingCredentialsProvider provider = new CognitoCachingCredentialsProvider(context,
         awsAccountId, identityPoolId, unauthRoleArn, authRoleArn, Regions.US_EAST_1);
 CognitoClientManager client = new CognitoClientManager(context, Regions.US_EAST_1, provider);
 
 Dataset dataset = client.openOrCreateDataset("default_dataset");
 dataset.put("high_score", "100");
 dataset.synchronize(new SyncCallback() {
     // override callbacks
 });
 


Constructor Summary
CognitoSyncManager(android.content.Context context, Regions region, CognitoCachingCredentialsProvider provider)
          Constructs a CognitoSyncManager object.
CognitoSyncManager(android.content.Context context, java.lang.String identityPoolId, Regions region, CognitoCachingCredentialsProvider provider)
          Deprecated. Please use the constructor without an identityPoolId
 
Method Summary
 PushSyncUpdate getPushSyncUpdate(android.content.Intent intent)
          Converts the notification from Cognito push sync to an object that has easy access to all of the relevant information.
 boolean isDeviceRegistered()
          Checks the cache to see if the registration information is saved
 java.util.List<DatasetMetadata> listDatasets()
          Retrieves a list of datasets from local storage.
 Dataset openOrCreateDataset(java.lang.String datasetName)
          Opens or creates a dataset.
 void refreshDatasetMetadata()
          Refreshes dataset metadata.
 void registerDevice(java.lang.String platform, java.lang.String token)
          Register device for push sync.
 void subscribe(java.util.List<java.lang.String> datasetNames)
          Subscribes the user to some set of datasets from the total list that the device knows of, giving the user push sync notifications for all in that set
 void subscribeAll()
          Subscribes the user to all datasets that the local device knows of for push sync notifications for all datasets
 void unregisterDevice()
          Unregisters the device for push sync.
 void unsubscribe(java.util.List<java.lang.String> datasetNames)
          Unsubscribes the user to some set of datasets from the total list that the device knows of, ending any reception of push sync notifications
 void unsubscribeAll()
          Unsubscribes the user to all datasets that the local device knows of from push sync notifications for all datasets
 void wipeData()
          Wipes all user data cached locally, including identity id, session credentials, dataset metadata, and all records.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CognitoSyncManager

@Deprecated
public CognitoSyncManager(android.content.Context context,
                                     java.lang.String identityPoolId,
                                     Regions region,
                                     CognitoCachingCredentialsProvider provider)
Deprecated. Please use the constructor without an identityPoolId

Constructs a CognitoSyncManager object.

Parameters:
context - a context of the app
identityPoolId - Cognito identity pool id
region - Cognito sync region
provider - a credentials provider

CognitoSyncManager

public CognitoSyncManager(android.content.Context context,
                          Regions region,
                          CognitoCachingCredentialsProvider provider)
Constructs a CognitoSyncManager object.

Parameters:
context - a context of the app
region - Cognito sync region
provider - a credentials provider
Method Detail

openOrCreateDataset

public Dataset openOrCreateDataset(java.lang.String datasetName)
Opens or creates a dataset. If the dataset doesn't exist, an empty one with the given name will be created. Otherwise, dataset is loaded from local storage. If a dataset is marked as deleted but hasn't been deleted on remote via refreshDatasetMetadata(), it will throw IllegalStateException.

Parameters:
datasetName - dataset name, must be [a-zA-Z0=9_.:-]+
Returns:
dataset loaded from local storage

listDatasets

public java.util.List<DatasetMetadata> listDatasets()
Retrieves a list of datasets from local storage. It may not reflects latest dataset on the remote storage until refreshDatasetMetadata is called.

Returns:
list of datasets

refreshDatasetMetadata

public void refreshDatasetMetadata()
                            throws DataStorageException
Refreshes dataset metadata. Dataset metadata is pulled from remote storage and stored in local storage. Their record data isn't pulled down until you sync each dataset. Note: this is a network request, so calling this method in the main thread will result in NetworkOnMainThreadException.

Throws:
DataStorageException - thrown when fail to fresh dataset metadata

wipeData

public void wipeData()
Wipes all user data cached locally, including identity id, session credentials, dataset metadata, and all records. Any data that hasn't been synced will be lost. This method should be called after logging out a customer.


registerDevice

public void registerDevice(java.lang.String platform,
                           java.lang.String token)
Register device for push sync. Upon calling this method, the device will be registered with the platform in use via Cognito, and reconcile that registration with the Cognito system

Parameters:
platform - Platform of the device, one of GCM, ADM
token - Device token of the device, gotten when registered for the platform in question.

isDeviceRegistered

public boolean isDeviceRegistered()
Checks the cache to see if the registration information is saved

Returns:
true if it has, false if it hasn't

unregisterDevice

public void unregisterDevice()
Unregisters the device for push sync. This will clear the local cache that blocks the device from registering, but not clearing the information from outside the device


subscribeAll

public void subscribeAll()
Subscribes the user to all datasets that the local device knows of for push sync notifications for all datasets


subscribe

public void subscribe(java.util.List<java.lang.String> datasetNames)
Subscribes the user to some set of datasets from the total list that the device knows of, giving the user push sync notifications for all in that set

Parameters:
datasetNames - The list of names of datasets to subscribe to

unsubscribeAll

public void unsubscribeAll()
Unsubscribes the user to all datasets that the local device knows of from push sync notifications for all datasets


unsubscribe

public void unsubscribe(java.util.List<java.lang.String> datasetNames)
Unsubscribes the user to some set of datasets from the total list that the device knows of, ending any reception of push sync notifications

Parameters:
datasetNames - The list of names of datasets to unsubscribe from

getPushSyncUpdate

public PushSyncUpdate getPushSyncUpdate(android.content.Intent intent)
Converts the notification from Cognito push sync to an object that has easy access to all of the relevant information.

Parameters:
extras - the bundle returned from the intent.getExtras() call
Returns:
the PushSyncUpdate that bundle is converted to


Copyright © 2010 Amazon Web Services, Inc. All Rights Reserved.