Join us for ⁠#Android11: The Beta Launch Show on June 3!
Added in API level 24
Deprecated in API level 29

ConditionProviderService

abstract class ConditionProviderService : Service
kotlin.Any
   ↳ android.content.Context
   ↳ android.content.ContextWrapper
   ↳ android.app.Service
   ↳ android.service.notification.ConditionProviderService

A service that provides conditions about boolean state.

To extend this class, you must declare the service in your manifest file with the android.Manifest.permission#BIND_CONDITION_PROVIDER_SERVICE permission and include an intent filter with the SERVICE_INTERFACE action. If you want users to be able to create and update conditions for this service to monitor, include the META_DATA_RULE_TYPE and META_DATA_CONFIGURATION_ACTIVITY tags and request the android.Manifest.permission#ACCESS_NOTIFICATION_POLICY permission. For example:

<service android:name=".MyConditionProvider"
           android:label="@string/service_name"
           android:permission="android.permission.BIND_CONDITION_PROVIDER_SERVICE">
      <intent-filter>
          <action android:name="android.service.notification.ConditionProviderService" />
      </intent-filter>
      <meta-data
                android:name="android.service.zen.automatic.ruleType"
                android:value="@string/my_condition_rule">
            </meta-data>
            <meta-data
                android:name="android.service.zen.automatic.configurationActivity"
                android:value="com.my.package/.MyConditionConfigurationActivity">
            </meta-data>
  </service>

Condition providers cannot be bound by the system on ActivityManager#isLowRamDevice() devices running Android Q (and below)

Summary

Constants

static String

A String rule id extra passed to META_DATA_CONFIGURATION_ACTIVITY.

static String

The name of the meta-data tag containing the ComponentName of an activity that allows users to configure the conditions provided by this service.

static String

The name of the meta-data tag containing the maximum number of rule instances that can be created for this rule type.

static String

The name of the meta-data tag containing a localized name of the type of zen rules provided by this service.

static String

The Intent that must be declared as handled by the service.

Inherited constants

Public constructors

Public methods

Unit

Informs the notification manager that the state of a Condition has changed.

Unit
notifyConditions(vararg conditions: Condition!)

Informs the notification manager that the state of one or more Conditions has changed.

open IBinder?
onBind(intent: Intent!)

abstract Unit

Called when this service is connected.

open Unit

abstract Unit
onSubscribe(conditionId: Uri!)

Called by the system when there is a new Condition to be managed by this provider.

abstract Unit
onUnsubscribe(conditionId: Uri!)

Called by the system when a Condition has been deleted.

static Unit
requestRebind(componentName: ComponentName!)

Request that the provider be rebound, after a previous call to (@link #requestUnbind).

Unit

Request that the provider service be unbound.

Inherited functions

Constants

EXTRA_RULE_ID

Added in API level 24
Deprecated in API level 29
static val EXTRA_RULE_ID: String

Deprecated: see android.app.NotificationManager#EXTRA_AUTOMATIC_RULE_ID.

A String rule id extra passed to META_DATA_CONFIGURATION_ACTIVITY.

Value: "android.service.notification.extra.RULE_ID"

META_DATA_CONFIGURATION_ACTIVITY

Added in API level 24
Deprecated in API level 29
static val META_DATA_CONFIGURATION_ACTIVITY: String

Deprecated: see android.app.NotificationManager#ACTION_AUTOMATIC_ZEN_RULE.

The name of the meta-data tag containing the ComponentName of an activity that allows users to configure the conditions provided by this service.

Value: "android.service.zen.automatic.configurationActivity"

META_DATA_RULE_INSTANCE_LIMIT

Added in API level 24
Deprecated in API level 29
static val META_DATA_RULE_INSTANCE_LIMIT: String

Deprecated: see android.app.NotificationManager#META_DATA_RULE_INSTANCE_LIMIT.

The name of the meta-data tag containing the maximum number of rule instances that can be created for this rule type. Omit or enter a value <= 0 to allow unlimited instances.

Value: "android.service.zen.automatic.ruleInstanceLimit"

META_DATA_RULE_TYPE

Added in API level 24
Deprecated in API level 29
static val META_DATA_RULE_TYPE: String

Deprecated: see android.app.NotificationManager#META_DATA_AUTOMATIC_RULE_TYPE.

The name of the meta-data tag containing a localized name of the type of zen rules provided by this service.

Value: "android.service.zen.automatic.ruleType"

SERVICE_INTERFACE

Added in API level 24
Deprecated in API level 29
static val SERVICE_INTERFACE: String

Deprecated.

The Intent that must be declared as handled by the service.

Value: "android.service.notification.ConditionProviderService"

Public constructors

<init>

ConditionProviderService()

Public methods

notifyCondition

Added in API level 24
Deprecated in API level 29
fun notifyCondition(condition: Condition!): Unit

Deprecated: see android.app.NotificationManager#setAutomaticZenRuleState(String, Condition).

Informs the notification manager that the state of a Condition has changed. Use this method to put the system into Do Not Disturb mode or request that it exits Do Not Disturb mode. This call will be ignored unless there is an enabled android.app.AutomaticZenRule owned by service that has an android.app.AutomaticZenRule#getConditionId() equal to this Condition#id.

Parameters
condition Condition!: the condition that has changed.

notifyConditions

Added in API level 24
Deprecated in API level 29
fun notifyConditions(vararg conditions: Condition!): Unit

Deprecated: see android.app.NotificationManager#setAutomaticZenRuleState(String, Condition).

Informs the notification manager that the state of one or more Conditions has changed. See notifyCondition(android.service.notification.Condition) for restrictions.

Parameters
conditions Condition!: the changed conditions.

onBind

Added in API level 24
Deprecated in API level 29
open fun onBind(intent: Intent!): IBinder?

Deprecated.

Parameters
intent Intent!: The Intent that was used to bind to this service, as given to 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.

onConnected

Added in API level 24
Deprecated in API level 29
abstract fun onConnected(): Unit

Deprecated.

Called when this service is connected.

onRequestConditions

Added in API level 24
Deprecated in API level 29
open fun onRequestConditions(relevance: Int): Unit

Deprecated.

onSubscribe

Added in API level 24
Deprecated in API level 29
abstract fun onSubscribe(conditionId: Uri!): Unit

Deprecated.

Called by the system when there is a new Condition to be managed by this provider.

Parameters
conditionId Uri!: the Uri describing the criteria of the condition.

onUnsubscribe

Added in API level 24
Deprecated in API level 29
abstract fun onUnsubscribe(conditionId: Uri!): Unit

Deprecated.

Called by the system when a Condition has been deleted.

Parameters
conditionId Uri!: the Uri describing the criteria of the deleted condition.

requestRebind

Added in API level 26
Deprecated in API level 29
static fun requestRebind(componentName: ComponentName!): Unit

Deprecated.

Request that the provider be rebound, after a previous call to (@link #requestUnbind).

This method will fail for providers that have not been granted the permission by the user.

requestUnbind

Added in API level 26
Deprecated in API level 29
fun requestUnbind(): Unit

Deprecated.

Request that the provider service be unbound.

This will no longer receive subscription updates and will not be able to update the state of conditions until requestRebind(android.content.ComponentName) is called. The service will likely be killed by the system after this call.

The service should wait for the onConnected() event before performing this operation.