ConditionProviderService

public abstract class ConditionProviderService
extends Service

java.lang.Object
   ↳ android.content.Context
     ↳ android.content.ContextWrapper
       ↳ android.app.Service
         ↳ android.service.notification.ConditionProviderService


This class was deprecated in API level 29.
Instead of using an automatically bound service, use NotificationManager.setAutomaticZenRuleState(String, Condition) to tell the system about the state of your rule. In order to maintain a link from Settings to your rule configuration screens, provide a configuration activity that handles NotificationManager.ACTION_AUTOMATIC_ZEN_RULE on your AutomaticZenRule via AutomaticZenRule.setConfigurationActivity(ComponentName).

A service that provides conditions about boolean state.

To extend this class, you must declare the service in your manifest file with the 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 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 low ram devices running Android Q (and below)

Summary

Constants

String EXTRA_RULE_ID

This constant is deprecated. see NotificationManager.EXTRA_AUTOMATIC_RULE_ID.

String META_DATA_CONFIGURATION_ACTIVITY

This constant is deprecated. see NotificationManager.ACTION_AUTOMATIC_ZEN_RULE.

String META_DATA_RULE_INSTANCE_LIMIT

This constant is deprecated. see NotificationManager.META_DATA_RULE_INSTANCE_LIMIT.

String META_DATA_RULE_TYPE

This constant is deprecated. see NotificationManager.META_DATA_AUTOMATIC_RULE_TYPE.

String SERVICE_INTERFACE

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

Inherited constants

Public constructors

ConditionProviderService()

Public methods

final void notifyCondition(Condition condition)

This method is deprecated. see NotificationManager.setAutomaticZenRuleState(String, Condition).

final void notifyConditions(Condition... conditions)

This method is deprecated. see NotificationManager.setAutomaticZenRuleState(String, Condition).

IBinder onBind(Intent intent)

Return the communication channel to the service.

abstract void onConnected()

Called when this service is connected.

void onRequestConditions(int relevance)
abstract void onSubscribe(Uri conditionId)

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

abstract void onUnsubscribe(Uri conditionId)

Called by the system when a Condition has been deleted.

static final void requestRebind(ComponentName componentName)

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

final void requestUnbind()

Request that the provider service be unbound.

Inherited methods

Constants

EXTRA_RULE_ID

Added in API level 24
public static final String EXTRA_RULE_ID

This constant is deprecated.
see NotificationManager.EXTRA_AUTOMATIC_RULE_ID.

A String rule id extra passed to META_DATA_CONFIGURATION_ACTIVITY.

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

META_DATA_CONFIGURATION_ACTIVITY

Added in API level 24
public static final String META_DATA_CONFIGURATION_ACTIVITY

This constant is deprecated.
see 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.

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

META_DATA_RULE_INSTANCE_LIMIT

Added in API level 24
public static final String META_DATA_RULE_INSTANCE_LIMIT

This constant is deprecated.
see 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.

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

META_DATA_RULE_TYPE

Added in API level 24
public static final String META_DATA_RULE_TYPE

This constant is deprecated.
see 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.

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

SERVICE_INTERFACE

Added in API level 24
public static final String SERVICE_INTERFACE

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

Constant Value: "android.service.notification.ConditionProviderService"

Public constructors

ConditionProviderService

public ConditionProviderService ()

Public methods

notifyCondition

Added in API level 24
public final void notifyCondition (Condition condition)

This method is deprecated.
see 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 AutomaticZenRule owned by service that has an AutomaticZenRule.getConditionId() equal to this Condition#id.

Parameters
condition Condition: the condition that has changed.

notifyConditions

Added in API level 24
public final void notifyConditions (Condition... conditions)

This method is deprecated.
see 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
public IBinder onBind (Intent intent)

Return the communication channel to the service. May return null if clients can not bind to the service. The returned IBinder is usually for a complex interface that has been described using aidl.

Note that unlike other application components, calls on to the IBinder interface returned here may not happen on the main thread of the process. More information about the main thread can be found in Processes and Threads.

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.

Returns
IBinder Return an IBinder through which clients can call on to the service.

onConnected

Added in API level 24
public abstract void onConnected ()

Called when this service is connected.

onRequestConditions

Added in API level 24
public void onRequestConditions (int relevance)

Parameters
relevance int

onSubscribe

Added in API level 24
public abstract void onSubscribe (Uri conditionId)

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
public abstract void onUnsubscribe (Uri conditionId)

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
public static final void requestRebind (ComponentName componentName)

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.

Parameters
componentName ComponentName

requestUnbind

Added in API level 26
Deprecated in API level 29
public final void requestUnbind ()

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.