Class SeriesGuideExtension
- java.lang.Object
-
- android.content.Context
-
- android.content.ContextWrapper
-
- android.app.Service
-
- androidx.core.app.JobIntentService
-
- com.battlelancer.seriesguide.api.SeriesGuideExtension
-
- All Implemented Interfaces:
ComponentCallbacks
,ComponentCallbacks2
public abstract class SeriesGuideExtension extends JobIntentService
Base class for a SeriesGuide extension. Extensions are a way for other apps to feed actions (represented through actions) for episodes and movies to SeriesGuide. Actions may for example launch other apps or display interesting information related to an episode or movie.Extensions are specialized
JobIntentService
classes in combination with a broadcast receiver.Multiple extensions may be enabled within SeriesGuide at the same time. When a SeriesGuide user chooses to enable an extension, SeriesGuide will subscribe to it prior of requesting actions. If the user disables the extension, SeriesGuide will unsubscribe from it.
The API is designed such that other applications besides SeriesGuide can subscribe and request actions from an extension.
Subclassing
Subclasses must at least implementSeriesGuideExtension
onRequest(int, Episode)
oronRequest(int, Movie)
, which is called when SeriesGuide requests actions to display for an episode or movie. Do not perform long running operations here as the user will get frustrated while waiting for the action to appear.To publish an action, call
publishAction(Action)
fromonRequest(int, Episode)
oronRequest(int, Movie)
. All current subscribers will then immediately receive an update with the new action information. Under the hood, this is done with broadcast intents.As the subclass is a
JobIntentService
, it needs be declared as a<service>
component in the application'sAndroidManifest.xml
. In addition it must be exported and given theJobService.PERMISSION_BIND
permission to integrate with the platforms job scheduler.Registering your extension
An extension is exposed through a broadcast receiver that SeriesGuide and other apps interact with via broadcast intents. This receiver enqueues requests from subscribers to be processed by this service. A simple receiver can be implemented by subclassingSeriesGuideExtensionReceiver
.The receiver must be declared as a
<receiver>
component in the application'sAndroidManifest.xml
file.The SeriesGuide app and other potential subscribers discover available extensions using Android's
Intent
mechanism. Ensure that yourreceiver
definition includes an<intent-filter>
with an action ofSeriesGuideExtensionReceiver.ACTION_SERIESGUIDE_EXTENSION
.To make your extension easier to identify for users you should add the following attributes to your receiver definition:
android:label
(optional): the name to display when displaying your extension in the user interface.android:description
(optional): a few words describing what your actions display or can do (e.g. "Displays interesting stat" or "Searches Google").android:icon
(optional): a drawable to represent the extension in the user interface.
If you want to provide a settings activity, add the following
<meta-data>
element to your receiver definition:settingsActivity
(optional): if present, should be the qualified component name for a configuration activity in the extension's package that SeriesGuide can offer to the user for customizing the extension. This activity must be exported.
Example
Below is an example extension declaration in the manifest:<receiver android:name=".ExampleExtensionReceiver" android:description="@string/extension_description" android:icon="@drawable/ic_extension_example" android:label="@string/extension_title"> <intent-filter> <action android:name="com.battlelancer.seriesguide.api.SeriesGuideExtension" /> </intent-filter> <!-- A settings activity is optional --> <meta-data android:name="settingsActivity" android:value=".ExampleSettingsActivity" /> </receiver> <service android:name=".ExampleExtension" android:exported="true" android:permission="android.permission.BIND_JOB_SERVICE" />
If asettingsActivity
meta-data element is present, an activity with the given component name should be defined and exported in the application's manifest as well. SeriesGuide will set theEXTRA_FROM_SERIESGUIDE_SETTINGS
extra to true in the launch intent for this activity. An example is shown below:<activity android:name=".ExampleSettingsActivity" android:label="@string/title_settings" android:exported="true" />
Finally, below are a simple exampleSeriesGuideExtensionReceiver
andSeriesGuideExtension
subclass that publishes actions for episodes performing a simple Google search:public class ExampleExtensionReceiver extends SeriesGuideExtensionReceiver { protected int getJobId() { return 1000; } protected Class<? extends SeriesGuideExtension> getExtensionClass() { return ExampleExtension.class; } } public class ExampleExtension extends SeriesGuideExtension { protected void onRequest(int episodeIdentifier, Episode episode) { publishAction(new Action.Builder("Google search", episodeIdentifier) .viewIntent(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse("https://www.google.com/#q=" + episode.getTitle()))) .build()); } }
Based on code from Muzei, an awesome Live Wallpaper by Roman Nurik.
-
-
Field Summary
Fields Modifier and Type Field Description static String
EXTRA_FROM_SERIESGUIDE_SETTINGS
Boolean extra that will be set to true when SeriesGuide starts the extensions (optionally) declared settings activity.-
Fields inherited from class android.app.Service
START_CONTINUATION_MASK, START_FLAG_REDELIVERY, START_FLAG_RETRY, START_NOT_STICKY, START_REDELIVER_INTENT, START_STICKY, START_STICKY_COMPATIBILITY, STOP_FOREGROUND_DETACH, STOP_FOREGROUND_REMOVE
-
Fields inherited from class android.content.Context
ACCESSIBILITY_SERVICE, ACCOUNT_SERVICE, ACTIVITY_SERVICE, ALARM_SERVICE, APP_OPS_SERVICE, APPWIDGET_SERVICE, AUDIO_SERVICE, BATTERY_SERVICE, BIND_ABOVE_CLIENT, BIND_ADJUST_WITH_ACTIVITY, BIND_ALLOW_OOM_MANAGEMENT, BIND_AUTO_CREATE, BIND_DEBUG_UNBIND, BIND_EXTERNAL_SERVICE, BIND_IMPORTANT, BIND_INCLUDE_CAPABILITIES, BIND_NOT_FOREGROUND, BIND_NOT_PERCEPTIBLE, BIND_WAIVE_PRIORITY, BIOMETRIC_SERVICE, BLOB_STORE_SERVICE, BLUETOOTH_SERVICE, CAMERA_SERVICE, CAPTIONING_SERVICE, CARRIER_CONFIG_SERVICE, CLIPBOARD_SERVICE, COMPANION_DEVICE_SERVICE, CONNECTIVITY_DIAGNOSTICS_SERVICE, CONNECTIVITY_SERVICE, CONSUMER_IR_SERVICE, CONTEXT_IGNORE_SECURITY, CONTEXT_INCLUDE_CODE, CONTEXT_RESTRICTED, CROSS_PROFILE_APPS_SERVICE, DEVICE_POLICY_SERVICE, DISPLAY_SERVICE, DOWNLOAD_SERVICE, DROPBOX_SERVICE, EUICC_SERVICE, FILE_INTEGRITY_SERVICE, FINGERPRINT_SERVICE, HARDWARE_PROPERTIES_SERVICE, INPUT_METHOD_SERVICE, INPUT_SERVICE, IPSEC_SERVICE, JOB_SCHEDULER_SERVICE, KEYGUARD_SERVICE, LAUNCHER_APPS_SERVICE, LAYOUT_INFLATER_SERVICE, LOCATION_SERVICE, MEDIA_PROJECTION_SERVICE, MEDIA_ROUTER_SERVICE, MEDIA_SESSION_SERVICE, MIDI_SERVICE, MODE_APPEND, MODE_ENABLE_WRITE_AHEAD_LOGGING, MODE_NO_LOCALIZED_COLLATORS, MODE_PRIVATE, NETWORK_STATS_SERVICE, NFC_SERVICE, NOTIFICATION_SERVICE, NSD_SERVICE, POWER_SERVICE, PRINT_SERVICE, RECEIVER_VISIBLE_TO_INSTANT_APPS, RESTRICTIONS_SERVICE, ROLE_SERVICE, SEARCH_SERVICE, SENSOR_SERVICE, SHORTCUT_SERVICE, STORAGE_SERVICE, STORAGE_STATS_SERVICE, SYSTEM_HEALTH_SERVICE, TELECOM_SERVICE, TELEPHONY_IMS_SERVICE, TELEPHONY_SERVICE, TELEPHONY_SUBSCRIPTION_SERVICE, TEXT_CLASSIFICATION_SERVICE, TEXT_SERVICES_MANAGER_SERVICE, TV_INPUT_SERVICE, UI_MODE_SERVICE, USAGE_STATS_SERVICE, USB_SERVICE, USER_SERVICE, VIBRATOR_SERVICE, VPN_MANAGEMENT_SERVICE, WALLPAPER_SERVICE, WIFI_AWARE_SERVICE, WIFI_P2P_SERVICE, WIFI_RTT_RANGING_SERVICE, WIFI_SERVICE, WINDOW_SERVICE
-
Fields inherited from interface android.content.ComponentCallbacks2
TRIM_MEMORY_BACKGROUND, TRIM_MEMORY_COMPLETE, TRIM_MEMORY_MODERATE, TRIM_MEMORY_RUNNING_CRITICAL, TRIM_MEMORY_RUNNING_LOW, TRIM_MEMORY_RUNNING_MODERATE, TRIM_MEMORY_UI_HIDDEN
-
-
Constructor Summary
Constructors Constructor Description SeriesGuideExtension(String name)
Call from your default constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Action
getCurrentAction()
Returns the most recently publishedAction
, or null if none was published, yet.protected SharedPreferences
getSharedPreferences()
Convenience method for accessing preferences specific to the extension.protected static SharedPreferences
getSharedPreferences(Context context, String extensionName)
Convenience method for accessing preferences specific to the extension (with the given name within this package.protected boolean
onAllowSubscription(ComponentName subscriber)
Method called before a new subscriber is added that determines whether the subscription is allowed or not.void
onCreate()
protected void
onDisabled()
Lifecycle method called when the last subscriber is removed.protected void
onEnabled()
Lifecycle method called when the first subscriber is added.protected void
onHandleWork(Intent intent)
protected void
onRequest(int episodeIdentifier, Episode episode)
Called when an episode is displayed and the extension should publish the action it wants to display usingpublishAction(Action)
.protected void
onRequest(int movieIdentifier, Movie movie)
Called when a movie is displayed and the extension should publish the action it wants to display usingpublishAction(Action)
.protected void
onSubscriberAdded(ComponentName subscriber)
Lifecycle method called when a new subscriber is added.protected void
onSubscriberRemoved(ComponentName subscriber)
Lifecycle method called when a subscriber is removed.protected void
publishAction(Action action)
Publishes the providedAction
.-
Methods inherited from class androidx.core.app.JobIntentService
enqueueWork, enqueueWork, isStopped, onBind, onDestroy, onStartCommand, onStopCurrentWork, setInterruptIfStopped
-
Methods inherited from class android.app.Service
attachBaseContext, dump, getApplication, getForegroundServiceType, onConfigurationChanged, onLowMemory, onRebind, onTaskRemoved, onTrimMemory, onUnbind, startForeground, startForeground, stopForeground, stopForeground, stopSelf, stopSelf, stopSelfResult
-
Methods inherited from class android.content.ContextWrapper
bindIsolatedService, bindService, bindService, bindServiceAsUser, checkCallingOrSelfPermission, checkCallingOrSelfUriPermission, checkCallingPermission, checkCallingUriPermission, checkPermission, checkSelfPermission, checkUriPermission, checkUriPermission, createAttributionContext, createConfigurationContext, createContextForSplit, createDeviceProtectedStorageContext, createDisplayContext, createPackageContext, createWindowContext, databaseList, deleteDatabase, deleteFile, deleteSharedPreferences, enforceCallingOrSelfPermission, enforceCallingOrSelfUriPermission, enforceCallingPermission, enforceCallingUriPermission, enforcePermission, enforceUriPermission, enforceUriPermission, fileList, getApplicationContext, getApplicationInfo, getAssets, getAttributionTag, getBaseContext, getCacheDir, getClassLoader, getCodeCacheDir, getContentResolver, getDatabasePath, getDataDir, getDir, getDisplay, getExternalCacheDir, getExternalCacheDirs, getExternalFilesDir, getExternalFilesDirs, getExternalMediaDirs, getFilesDir, getFileStreamPath, getMainExecutor, getMainLooper, getNoBackupFilesDir, getObbDir, getObbDirs, getOpPackageName, getPackageCodePath, getPackageManager, getPackageName, getPackageResourcePath, getResources, getSharedPreferences, getSystemService, getSystemServiceName, getTheme, grantUriPermission, isDeviceProtectedStorage, isRestricted, moveDatabaseFrom, moveSharedPreferencesFrom, openFileInput, openFileOutput, openOrCreateDatabase, openOrCreateDatabase, registerReceiver, registerReceiver, registerReceiver, registerReceiver, revokeUriPermission, revokeUriPermission, sendBroadcast, sendBroadcast, sendBroadcastAsUser, sendBroadcastAsUser, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcastAsUser, setTheme, startActivities, startActivities, startActivity, startActivity, startForegroundService, startInstrumentation, startIntentSender, startIntentSender, startService, stopService, unbindService, unregisterReceiver, updateServiceGroup
-
Methods inherited from class android.content.Context
getColor, getColorStateList, getDrawable, getString, getString, getSystemService, getText, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, registerComponentCallbacks, sendBroadcastWithMultiplePermissions, unregisterComponentCallbacks
-
-
-
-
Field Detail
-
EXTRA_FROM_SERIESGUIDE_SETTINGS
public static final String EXTRA_FROM_SERIESGUIDE_SETTINGS
Boolean extra that will be set to true when SeriesGuide starts the extensions (optionally) declared settings activity. Check for this extra in your settings activity if you need to adjust your UI depending on whether or not the user came from SeriesGuide's settings screen.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SeriesGuideExtension
public SeriesGuideExtension(String name)
Call from your default constructor.- Parameters:
name
- Gives the extension a name. This is not user-visible, but will be used to store preferences and state for the extension.
-
-
Method Detail
-
onCreate
public void onCreate()
- Overrides:
onCreate
in classJobIntentService
-
getSharedPreferences
protected static SharedPreferences getSharedPreferences(Context context, String extensionName)
Convenience method for accessing preferences specific to the extension (with the given name within this package. The source name must be the one provided in theSeriesGuideExtension(String)
constructor. This static method is useful for exposing extension preferences to other application components such as a settings activity.- Parameters:
context
- The context; can be an application context.extensionName
- The source name, provided in theSeriesGuideExtension(String)
constructor.
-
getSharedPreferences
protected final SharedPreferences getSharedPreferences()
Convenience method for accessing preferences specific to the extension.
-
onAllowSubscription
protected boolean onAllowSubscription(ComponentName subscriber)
Method called before a new subscriber is added that determines whether the subscription is allowed or not. The default behavior is to allow all subscriptions.- Returns:
- true if the subscription should be allowed, false if it should be denied.
-
onSubscriberAdded
protected void onSubscriberAdded(ComponentName subscriber)
Lifecycle method called when a new subscriber is added. Extensions generally don't need to override this.
-
onSubscriberRemoved
protected void onSubscriberRemoved(ComponentName subscriber)
Lifecycle method called when a subscriber is removed. Extensions generally don't need to override this.
-
onEnabled
protected void onEnabled()
Lifecycle method called when the first subscriber is added. This will be called beforeonSubscriberAdded(ComponentName)
. Extensions generally don't need to override this.
-
onDisabled
protected void onDisabled()
Lifecycle method called when the last subscriber is removed. This will be called afteronSubscriberRemoved(ComponentName)
. Extensions generally don't need to override this.
-
onRequest
protected void onRequest(int episodeIdentifier, Episode episode)
Called when an episode is displayed and the extension should publish the action it wants to display usingpublishAction(Action)
.- Parameters:
episodeIdentifier
- The episode identifier the extension should submit with the action it wants to publish.
-
onRequest
protected void onRequest(int movieIdentifier, Movie movie)
Called when a movie is displayed and the extension should publish the action it wants to display usingpublishAction(Action)
.- Parameters:
movieIdentifier
- The movie identifier the extension should submit with the action it wants to publish.
-
publishAction
protected final void publishAction(Action action)
Publishes the providedAction
. It will be sent to all current subscribers.
-
getCurrentAction
protected final Action getCurrentAction()
Returns the most recently publishedAction
, or null if none was published, yet.
-
onHandleWork
protected void onHandleWork(@NonNull Intent intent)
- Specified by:
onHandleWork
in classJobIntentService
-
-