Added in API level 23
Deprecated in API level 30

ChooserTargetService


abstract class ChooserTargetService : Service
kotlin.Any
   ↳ android.content.Context
   ↳ android.content.ContextWrapper
   ↳ android.app.Service
   ↳ android.service.chooser.ChooserTargetService

A service that receives calls from the system when the user is asked to choose a target for an intent explicitly by another app. The calling app must have invoked ACTION_CHOOSER as handled by the system; applications do not have the ability to query a ChooserTargetService directly.

Which ChooserTargetServices are queried depends on a system-level policy decision made at the moment the chooser is invoked, including but not limited to user time spent with the app package or associated components in the foreground, recency of usage or frequency of usage. These will generally correlate with the order that app targets are shown in the list of intent handlers shown in the system chooser or resolver.

To extend this class, you must declare the service in your manifest file with the android.Manifest.permission#BIND_CHOOSER_TARGET_SERVICE permission and include an intent filter with the SERVICE_INTERFACE action. For example:

<service android:name=".MyChooserTargetService"
              android:label="@string/service_name"
              android:permission="android.permission.BIND_CHOOSER_TARGET_SERVICE">
          <intent-filter>
              <action android:name="android.service.chooser.ChooserTargetService" />
          </intent-filter>
      </service>
  

For the system to query your service, you must add a <meta-data> element to the Activity in your manifest that can handle Intents that you would also like to provide optional deep links for. For example, a chat app might offer deep links to recent active conversations instead of invoking a generic picker after the app itself is chosen as a target.

The meta-data element should have the name android.service.chooser.chooser_target_service and a value corresponding to the component name of your service. Example:

<activity android:name=".MyShareActivity"
              android:label="@string/share_activity_label">
          <intent-filter>
              <action android:name="android.intent.action.SEND" />
          </intent-filter>
          <meta-data android:name="android.service.chooser.chooser_target_service"
                  android:value=".MyChooserTargetService" />
      </activity>
  

Summary

Constants
static String

The permission that a ChooserTargetService must require in order to bind to it.

static String

The name of the meta-data element that must be present on an activity element in a manifest to link it to a ChooserTargetService

static String

The Intent action that a ChooserTargetService must respond to

Inherited constants
Public constructors

Public methods
open IBinder?
onBind(intent: Intent!)

abstract MutableList<ChooserTarget!>!
onGetChooserTargets(targetActivityName: ComponentName!, matchedFilter: IntentFilter!)

Called by the system to retrieve a set of deep-link targets that can handle an intent.

Inherited functions

Constants

BIND_PERMISSION

Added in API level 23
static val BIND_PERMISSION: String

Deprecated: Deprecated in Java.

The permission that a ChooserTargetService must require in order to bind to it. If this permission is not enforced the system will skip that ChooserTargetService.

Value: "android.permission.BIND_CHOOSER_TARGET_SERVICE"

META_DATA_NAME

Added in API level 23
static val META_DATA_NAME: String

Deprecated: Deprecated in Java.

The name of the meta-data element that must be present on an activity element in a manifest to link it to a ChooserTargetService

Value: "android.service.chooser.chooser_target_service"

SERVICE_INTERFACE

Added in API level 23
static val SERVICE_INTERFACE: String

Deprecated: Deprecated in Java.

The Intent action that a ChooserTargetService must respond to

Value: "android.service.chooser.ChooserTargetService"

Public constructors

ChooserTargetService

ChooserTargetService()

Public methods

onBind

Added in API level 23
open fun onBind(intent: Intent!): IBinder?

Deprecated: Deprecated in Java.

Parameters
intent Intent!: The Intent that was used to bind to this service, as given to android.content.Context#bindService. Note that any extras that were included with the Intent at that point will not be seen here.
Return
IBinder? Return an IBinder through which clients can call on to the service.

onGetChooserTargets

Added in API level 23
abstract fun onGetChooserTargets(
    targetActivityName: ComponentName!,
    matchedFilter: IntentFilter!
): MutableList<ChooserTarget!>!

Deprecated: Deprecated in Java.

Called by the system to retrieve a set of deep-link targets that can handle an intent.

The returned list should be sorted such that the most relevant targets appear first. The score for each ChooserTarget will be combined with the system's score for the original target Activity to sort and filter targets presented to the user.

Important: Calls to this method from other applications will occur on a binder thread, not on your app's main thread. Make sure that access to relevant data within your app is thread-safe.

Parameters
targetActivityName ComponentName!: the ComponentName of the matched activity that referred the system to this ChooserTargetService
matchedFilter IntentFilter!: the specific IntentFilter on the component that was matched
Return
MutableList<ChooserTarget!>! a list of deep-link targets to fulfill the intent match, sorted by relevance