About Shares

About Shares

Contents

Introduction

Call getShares method to list shares created for files or folders in a user’s Personal Cloud Storage account. Use deleteShares method to delte the specified share.

Example

createShare

  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. Create an ArrayList of ShareResource class.
  5. Retrieve resources to be shared from the cloud by calling fullview, getPhotos, getVideos, getDocuments, getPlaylists or metadata
  6. Create a share by calling CloudAPI#createShare.

Code Sample

try {
    ArrayList<ShareResource> shareResources = new ArrayList<>();
    
    for (int count=0; count<fullviewList.getCount(); count++) {
    	FullviewItem fullviewItem = fullviewList.getItem(count);
    	ShareResource resource = new ShareResource();
	    resource.setName(fullviewItem.getName());
    	resource.setLocation(fullviewItem.getUri());
	    resource.setSize(fullviewItem.getSize());
	    resource.setType("file");
	    resource.setSubType("image");
		shareResources.add(resource);
    }
    
    Share share = cloudAPI.createShare(contextWeakReference.get(), "New Share 1", 0, shareResources);
    Log.d("Create Share", "New Share UID: " + share.getUid());
 } catch (CloudAPIException cloudAPIException) {
    if (cloudAPIException.getCode() == CloudAPIException.ErrorCode.USER_UNAUTHORIZED) {
        Log.d("Create Share", "User not authorized, please call CloudAPI#authorize()");
    }
}

deleteShares

The following code sample deletes a specified share using shareUid. shareUidis a unique share identifier included in the response to getShares call.

  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 code samples listed below to delete shares.

Code Sample

try {
    boolean deleteSuccess = cloudAPI.deleteShares(context, shareUid);
	if (deleteSuccess) {
        Log.d("Shares", "Share Deleted");
    }
} catch (CloudAPIException cloudAPIException) {
    if (cloudAPIException.getCode() == CloudAPIException.ErrorCode.USER_UNAUTHORIZED) {
        Log.d("Delete Shares", "User not authorized, please call CloudAPI#authorize()");
    }
}

getShares

  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 code samples listed below to list shares.

The following code sample illustrates two examples: - How to retrieve shared created between two specified dates. - How to retrieve all shares in a user’s Personal Cloud Storage account.

Code Sample

The following code sample allows you to retrieve all shares created between specified dates.

try {
    ItemList<Share> itemListShares = cloudAPI.getShares(context, "2016-01-01T12:00:00Z", "2016-05-05T13:15:30Z");
    for (int shareCounter=0; shareCounter<itemListShares.getCount(); shareCounter++) {
        Share share = itemListShares.getItem(shareCounter);
        Log.d("Share", "Name: " + share.getName() + " - UID:" + share.getUid());
        ItemList<Share.Resource> resourceList = share.getResources();
        for (int resourceCounter=0; resourceCounter<resourceList.getCount(); resourceCounter++) {
        	Share.Resource resource = resourceList.getItem(resourceCounter);
        	Log.d("Share Resource", "Name: " + resource.getName() + " Url: " + resource.getUrl());
        }
	}
} catch (CloudAPIException cloudAPIException) {
    if (cloudAPIException.getCode() == CloudAPIException.ErrorCode.USER_UNAUTHORIZED) {
        Log.d("List Share", "User not authorized, please call CloudAPI#authorize()");
    }
}

NOTE:

To retrieve all shares, replace the following code in the code sample above:

ItemList<Share> itemListShares = cloudAPI.getShares(context, "2016-01-01T12:00:00Z", "2016-05-05T13:15:30Z");

with this code sample:

ItemList<Share> itemListShares = cloudAPI.getShares(context, null, null);

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