About Favorites

About Favorites

Introduction

  1. Add Cloud SDK for Android to an existing or a new Android project.
  2. Initialize the CloudAPI class object with the application key, secret and the callback URL you obtained from the ThingSpace portal.
  3. Authorize the application by calling CloudAPI#authorize().
  4. Use the code sample below to list all contacts stored in the user’s Personal Cloud Storage Account.

Examples

deleteFavorite

Code Sample

try {
	// Below is an example of how getPhotos() can be used to delete a favorite
	ItemList<Photo> itemListPhotos = cloudAPI.getPhotos(context, SortType.VERSION_CREATED.setOrder(SortType.SortOrder.DESC));
	
	// Alternatively, list items returend by fullview, metadata, search, getVideos, getAudios, getDocuments can also be used to retrieve Uri.
	
	boolean success = cloudAPI.deleteFavorite(context, itemListPhotos.getItem(0).getUri());
	Log.d("Delete Favorite", "Favorite Deleted: " + success);
	
} catch (CloudAPIException cloudAPIException) {
    if (cloudAPIException.getCode() == CloudAPIException.ErrorCode.USER_UNAUTHORIZED) {
		Log.d("Delete Favorite", "User not authorized, please call CloudAPI#authorize()");
    }
}

getFavorites

Code Sample

try {
	// Retrieve favorite Photos
	ItemList<Photo> favoritesListPhotos = cloudAPI.getFavorites(context, ResourceType.PHOTO);
	Photo photo = favoritesListPhotos.getItem(0);
	
	// Retrieve favorite Videos
	ItemList<Video> favoritesListVideos = cloudAPI.getFavorites(context, ResourceType.VIDEO);
	Video Video = favoritesListVideos.getItem(0);
	
	// Retrieve favorite Audio files
	ItemList<Audio> favoritesListAudios = cloudAPI.getFavorites(context, ResourceType.AUDIO);
	Audio audio = favoritesListAudios.getItem(0);
	
	// Retrieve all favorites
	ItemList<ResourceItem> favoritesList = cloudAPI.getFavorites(context, ResourceType.ALL);
	ResourceItem resource = favoritesList.getItem(0);
	// resource can be further type casted to Photo, Video, Audio, File or Folder 
	
} catch (CloudAPIException cloudAPIException) {
    if (cloudAPIException.getCode() == CloudAPIException.ErrorCode.USER_UNAUTHORIZED) {
		Log.d("Get Favorites", "User not authorized, please call CloudAPI#authorize()");
    }
}

setFavorites

Code Sample

try {
	// Below is an example of how getPhotos() can be used to set favorites
	ItemList<Photo> itemListPhotos = cloudAPI.getPhotos(context, SortType.VERSION_CREATED.setOrder(SortType.SortOrder.DESC));
	ArrayList<String> uris = new ArrayList<>();
	uris.add(itemListPhotos.getItem(0).getUri());
	uris.add(itemListPhotos.getItem(1).getUri());
	
	// Alternatively, list items returend by fullview, metadata, search, getVideos, getAudios, getDocuments can also be used to retrieve Uri.
	
	boolean success = cloudAPI.setFavorites(context, uris);
	Log.d("Set Favorites", "Favorite Set: " + success);
	
} catch (CloudAPIException cloudAPIException) {
    if (cloudAPIException.getCode() == CloudAPIException.ErrorCode.USER_UNAUTHORIZED) {
		Log.d("Set Favorites", "User not authorized, please call CloudAPI#authorize()");
    }
}

Copyright © 2015-2017, Verizon and/or its Licensors. All rights reserved.