Skip to content

Most visited

Recently visited

navigation

ConditionProviderService

public abstract class ConditionProviderService
extends Service

java.lang.Object
   ↳ 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 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 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>

Summary

Constants

String EXTRA_RULE_ID

A String rule id extra passed to META_DATA_CONFIGURATION_ACTIVITY.

String META_DATA_CONFIGURATION_ACTIVITY

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

String 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.

String META_DATA_RULE_TYPE

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

String SERVICE_INTERFACE

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

Inherited constants

From class android.app.Service
From class android.content.Context
From interface android.content.ComponentCallbacks2

Public constructors

ConditionProviderService()

Public methods

final void notifyCondition(Condition condition)

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

final void notifyConditions(Condition... conditions)

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

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

From class android.app.Service
From class android.content.ContextWrapper
From class android.content.Context
From class java.lang.Object
From interface android.content.ComponentCallbacks2
From interface android.content.ComponentCallbacks

Constants

EXTRA_RULE_ID

added in API level 24
String EXTRA_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
String META_DATA_CONFIGURATION_ACTIVITY

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
String 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
String META_DATA_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
String SERVICE_INTERFACE

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

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

Public constructors

ConditionProviderService

added in API level 24
ConditionProviderService ()

Public methods

notifyCondition

added in API level 24
void notifyCondition (Condition 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 getConditionId() equal to this id.

Parameters
condition Condition: the condition that has changed.

notifyConditions

added in API level 24
void notifyConditions (Condition... conditions)

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

Parameters
conditions Condition: the changed conditions.

onBind

added in API level 24
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
void onConnected ()

Called when this service is connected.

onRequestConditions

added in API level 24
void onRequestConditions (int relevance)

Parameters
relevance int

onSubscribe

added in API level 24
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
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
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
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(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.

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.