Once the SDK integrated and your PlatformClient
set-up, you are ready to query your content and retrieve your photos and videos.
1. Get your content
You can simply retrieve your content stored in Newzulu Platform using the fetchMedias
function of the client.
Here's how to do it:
public class YourActivity extends AppCompatActivity
{
...
private void retrieveMedias()
{
// Those are the options of your query, see #3 to use it
final PlatformClient.FetchMediasOptions options = new PlatformClient.FetchMediasOptions.Builder().build();
getPlatformClient().fetchMedias(options, new Request.ResponseListener<FetchResult<Media>>()
{
@Override
public void onResponse(@NonNull final FetchResult<Media> response)
{
// Your medias are available here, see #2 to use them
}
}, new Request.ErrorListener<PlatformException>()
{
@Override
public void onError(@NonNull final PlatformException e)
{
// An error occurred, see #4 to handle it
}
});
}
private PlatformClient getPlatformClient()
{
return ((YourApplication getApplication()).getPlatformClient();
}
}
Note that all SDK callbacks are done on the UI thread. It's safe to update your UI from them.
2. Use your medias
The Media
object is a wrapper around both images and videos. You can know which type of media it contains by calling getType()
:
if( media.getType() == MediaType.IMAGE )
{
// The media is an image (png, jpeg)
}
else if( media.getType() == MediaType.VIDEO )
{
// The media is a video (mp4, mpeg)
}
You have access to:
getId()
: a unique ID for this mediagetUrl()
: URL of the media at full resolutiongetThumbnailUrl()
: link to a thumbnail image representing the media. It will always be available for both images and videos. Note that this thumbnail is an image even for videos.getTitle()
: title of the mediagetWidth()
andgetHeight()
: dimensions of the full resolution mediagetOwner()
: aUser
object that contains data about the person who uploaded this mediagetDate()
: upload date of the media
3. Pagination
The SDK will return 25 items maximum per query and comes with a pagination API.
The fetchMedias
function takes options as first parameter that contain the page (default is 0). You can use it this way:
new PlatformClient.FetchMediasOptions.Builder()
.setPage(1)
.build();
Let's say you have 40 medias in your project, calling setPage(0)
will return the first 25 and calling setPage(1)
will return the next 15.
You can know if there's more media to query in the onResponse
callback: if calling response.hasMore()
returns true, you can increment the page and start a new query.
4. Handle errors
If the SDK fails to retrieve content, the onError
callback will be called with a PlatformException
that contains information about the encountered error.
You can call getType()
on the exception to get the type of error, here's the list of possible values:
NETWORK
: A network error occurred and the SDK was unable to reach the remote serviceSERVICE_ERROR
: The remote service encountered an error, you should try again laterUNKNOWN
: An unknown internal error occurred