lightbulb_outline Help shape the future of the Google Play Console, Android Studio, and Firebase. Start survey

ComplicationHelperActivity

public class ComplicationHelperActivity
extends Activity implements ActivityCompat.OnRequestPermissionsResultCallback

java.lang.Object
   ↳ android.content.Context
     ↳ android.content.ContextWrapper
       ↳ android.view.ContextThemeWrapper
         ↳ android.app.Activity
           ↳ android.support.wearable.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(Context, ComponentName, int, int...) 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 TYPE_NO_PERMISSION has been received and tapped on, use createPermissionRequestHelperIntent(Context, ComponentName).

Summary

Inherited constants

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

Inherited fields

From class android.app.Activity

Public constructors

ComplicationHelperActivity()

Public methods

static Intent createPermissionRequestHelperIntent(Context context, ComponentName watchFace)

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(Context context, ComponentName watchFace, int watchFaceComplicationId, int... supportedTypes)

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

void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)

Protected methods

void onActivityResult(int requestCode, int resultCode, Intent data)
void onCreate(Bundle savedInstanceState)

Inherited methods

From class android.app.Activity
From class android.view.ContextThemeWrapper
From class android.content.ContextWrapper
From class android.content.Context
From class java.lang.Object
From interface android.view.LayoutInflater.Factory2
From interface android.view.Window.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.View.OnCreateContextMenuListener
From interface android.content.ComponentCallbacks2
From interface android.support.v4.app.ActivityCompat.OnRequestPermissionsResultCallback
From interface android.view.LayoutInflater.Factory
From interface android.content.ComponentCallbacks

Public constructors

ComplicationHelperActivity

ComplicationHelperActivity ()

Public methods

createPermissionRequestHelperIntent

Intent createPermissionRequestHelperIntent (Context context, 
                ComponentName watchFace)

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

Returns
Intent

createProviderChooserHelperIntent

Intent createProviderChooserHelperIntent (Context context, 
                ComponentName watchFace, 
                int watchFaceComplicationId, 
                int... supportedTypes)

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 startActivityForResult(Intent, int). 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 RESULT_CANCELED 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 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 setActiveComplications(int...).

supportedTypes int: 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.

Returns
Intent

onRequestPermissionsResult

void onRequestPermissionsResult (int requestCode, 
                String[] permissions, 
                int[] grantResults)

Parameters
requestCode int

permissions String

grantResults int

Protected methods

onActivityResult

void onActivityResult (int requestCode, 
                int resultCode, 
                Intent data)

Parameters
requestCode int

resultCode int

data Intent

onCreate

void onCreate (Bundle savedInstanceState)

Parameters
savedInstanceState Bundle