Android Components > Service > Pocket
A library for easily getting Pocket recommendations that transparently handles downloading, caching and periodically refreshing Pocket data.
Currently this supports:
- Pocket recommended stories.
- Pocket sponsored stories.
Usage
-
For Pocket recommended stories:
- Use
PocketStoriesService#startPeriodicStoriesRefreshandPocketStoriesService#stopPeriodicStoriesRefreshas high up in the client app as possible (preferably in the Application object or in a single Activity) to ensure the background story refresh functionality works for the entirety of the app lifetime. - Use
PocketStoriesService.getStoriesto get the current list of Pocket recommended stories.
- Use
-
For Pocket sponsored stories:
- Use
PocketStoriesService#startPeriodicSponsoredStoriesRefreshandPocketStoriesService#stopPeriodicSponsoredStoriesRefreshas high up in the client app as possible (preferably in the Application object or in a single Activity) to ensure the background story refresh functionality works for the entirety of the app lifetime. - Use
PocketStoriesService.getSponsoredStoriesto get the current list of Pocket recommended stories. - Use
PocketStoriesService,recordStoriesImpressionsto try and persist that a list of sponsored stories were shown to the user. (Safe to call even if those stories are not persisted). - Use
PocketStoriesService.deleteProfileto delete all server stored information about the device to which sponsored stories were previously downloaded. This may include data like network ip and application tokens.
Pacing and rotating:
A new
PocketSponsoredStoryCapsis available in the response fromPocketStoriesService.getSponsoredStorieswhich allows checkingcurrentImpressions,lifetimeCount,flightCount,flightPeriodbased on which the client can decide which stories to show. All this is based on clients callingPocketStoriesService,recordStoriesImpressionsto record new impressions in between application restarts. - Use
Setting up the dependency
Use Gradle to download the library from maven.mozilla.org (Setup repository):
implementation "org.mozilla.components:service-pocket:{latest-version}"
License
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/