Google is committed to advancing racial equity for Black communities. See how.

ComplicationHelperActivity

class ComplicationHelperActivity : Activity, ActivityCompat.OnRequestPermissionsResultCallback
kotlin.Any
   ↳ android.content.Context
   ↳ android.content.ContextWrapper
   ↳ android.view.ContextThemeWrapper
   ↳ android.app.Activity
   ↳ androidx.wear.complications.ComplicationHelperActivity

Activity to handle permission requests for complications.

This can be used to start the provider chooser, making a permission request if necessary, or to just make a permission request, and update all active complications if the permission is granted.

To use, add this activity to your app, and also add the com.google.android.wearable.permission.RECEIVE_COMPLICATION_DATA permission.

Then, to start the provider chooser, use createProviderChooserHelperIntent to obtain an intent. If the permission has not yet been granted, the permission will be requested and the provider chooser will only be started if the request is accepted by the user.

Or, to request the permission, for instance if ComplicationData of has been received and tapped on, use createPermissionRequestHelperIntent.

Summary

Public constructors

Activity to handle permission requests for complications.

Public methods
static Intent
createPermissionRequestHelperIntent(@NonNull context: Context, @NonNull watchFace: ComponentName)

Returns an intent that may be used to start this activity in order to request the permission required to receive complication data.

static Intent
createProviderChooserHelperIntent(@NonNull context: Context, @NonNull watchFace: ComponentName, watchFaceComplicationId: Int, @NonNull supportedTypes: IntArray)

Returns an intent that may be used to start the provider chooser activity via the ComplicationHelperActivity.

Unit
onRequestPermissionsResult(requestCode: Int, @NonNull permissions: Array<String!>, @NonNull grantResults: IntArray)

Protected methods
Unit
onActivityResult(requestCode: Int, resultCode: Int, @Nullable data: Intent?)

Unit
onCreate(@Nullable savedInstanceState: Bundle?)

Public constructors

<init>

ComplicationHelperActivity()

Activity to handle permission requests for complications.

This can be used to start the provider chooser, making a permission request if necessary, or to just make a permission request, and update all active complications if the permission is granted.

To use, add this activity to your app, and also add the com.google.android.wearable.permission.RECEIVE_COMPLICATION_DATA permission.

Then, to start the provider chooser, use createProviderChooserHelperIntent to obtain an intent. If the permission has not yet been granted, the permission will be requested and the provider chooser will only be started if the request is accepted by the user.

Or, to request the permission, for instance if ComplicationData of has been received and tapped on, use createPermissionRequestHelperIntent.

Public methods

createPermissionRequestHelperIntent

@NonNull static fun createPermissionRequestHelperIntent(
    @NonNull context: Context,
    @NonNull watchFace: ComponentName
): Intent

Returns an intent that may be used to start this activity in order to request the permission required to receive complication data.

To use this, the ComplicationHelperActivity must be added to your app, and your app must include the com.google.android.wearable.permission.RECEIVE_COMPLICATION_DATA permission in its manifest.

If the current app has already been granted this permission, the activity will finish immediately.

If the current app has not been granted this permission, a permission request will be made. If the permission is granted by the user, an update of all complications on the current watch face will be triggered. The provided watchFace must match the current watch face for this to occur.

Parameters
context Context: context for the current app, that must contain a ComplicationHelperActivity
watchFace ComponentName: the ComponentName of the WatchFaceService for the current watch face

createProviderChooserHelperIntent

@NonNull static fun createProviderChooserHelperIntent(
    @NonNull context: Context,
    @NonNull watchFace: ComponentName,
    watchFaceComplicationId: Int,
    @NonNull supportedTypes: IntArray
): Intent

Returns an intent that may be used to start the provider chooser activity via the ComplicationHelperActivity. This allows the required permission to be checked before the provider chooser is displayed.

To use this, the ComplicationHelperActivity must be added to your app, and your app must include the com.google.android.wearable.permission.RECEIVE_COMPLICATION_DATA permission in its manifest.

The provider chooser activity will show a list of all providers that can supply data of at least one of the supportedTypes.

When the user chooses a provider, the configuration will be set up in the complications system - the watch face does not need to do anything else.

The activity may be started using Activity#startActivityForResult. The result delivered back to your activity will have a result code of RESULT_OK if a provider was successfully set, or a result code of if no provider was set. In the case where a provider was set, ComplicationProviderInfo for the chosen provider will be included in the data intent of the result, as an extra with the key android.support.wearable.complications.EXTRA_PROVIDER_INFO.

The package of the calling app must match the package of the watch face, or this will not work.

Parameters
context Context: context for the current app, that must contain a ComplicationHelperActivity
watchFace ComponentName: the ComponentName of the WatchFaceService being configured.
watchFaceComplicationId Int: the watch face's id for the complication being configured. This must match the id passed in when the watch face calls WatchFaceService.Engine#setActiveComplications.
supportedTypes IntArray: the types supported by the complication, in decreasing order of preference. If a provider can supply data for more than one of these types, the type chosen will be whichever was specified first.

onRequestPermissionsResult

fun onRequestPermissionsResult(
    requestCode: Int,
    @NonNull permissions: Array<String!>,
    @NonNull grantResults: IntArray
): Unit

Protected methods

onActivityResult

protected fun onActivityResult(
    requestCode: Int,
    resultCode: Int,
    @Nullable data: Intent?
): Unit

onCreate

protected fun onCreate(@Nullable savedInstanceState: Bundle?): Unit