CopaApp
Change of Plan Application
 All Classes Functions Variables Pages
Static Public Member Functions | Static Public Attributes | List of all members
unicopa.copa.app.gcm.GCMRegistrar Class Reference

Utilities for device registration. More...

Collaboration diagram for unicopa.copa.app.gcm.GCMRegistrar:
Collaboration graph

Static Public Member Functions

static void checkDevice (Context context)
 Checks if the device has the proper dependencies installed. More...
 
static void checkManifest (Context context)
 Checks that the application manifest is properly configured. More...
 
static void register (Context context, String...senderIds)
 Initiate messaging registration for the current application. More...
 
static void unregister (Context context)
 Unregister the application. More...
 
static synchronized void onDestroy (Context context)
 Clear internal resources. More...
 
static String getRegistrationId (Context context)
 Gets the current registration id for application on GCM service. More...
 
static boolean isRegistered (Context context)
 Checks whether the application was successfully registered on GCM service.
 
static void setRegisteredOnServer (Context context, boolean flag)
 Sets whether the device was successfully registered in the server side.
 
static boolean isRegisteredOnServer (Context context)
 Checks whether the device was successfully registered in the server side, as set by setRegisteredOnServer(Context, boolean). More...
 
static long getRegisterOnServerLifespan (Context context)
 Gets how long (in milliseconds) the isRegistered(Context) property is valid. More...
 
static void setRegisterOnServerLifespan (Context context, long lifespan)
 Sets how long (in milliseconds) the isRegistered(Context) flag is valid.
 

Static Public Attributes

static final long DEFAULT_ON_SERVER_LIFESPAN_MS
 Default lifespan (7 days) of the isRegisteredOnServer(Context) flag until it is considered expired. More...
 

Detailed Description

Utilities for device registration.

Note: this class uses a private SharedPreferences object to keep track of the registration token.

Member Function Documentation

static void unicopa.copa.app.gcm.GCMRegistrar.checkDevice ( Context  context)
static

Checks if the device has the proper dependencies installed.

This method should be called when the application starts to verify that the device supports GCM.

Parameters
contextapplication context.
Exceptions
UnsupportedOperationExceptionif the device does not support GCM.
static void unicopa.copa.app.gcm.GCMRegistrar.checkManifest ( Context  context)
static

Checks that the application manifest is properly configured.

A proper configuration means:

  1. It creates a custom permission called
    PACKAGE_NAME.permission.C2D_MESSAGE
    .
  2. It defines at least one BroadcastReceiver with category
    PACKAGE_NAME
    .
  3. The BroadcastReceiver(s) uses the { GCMConstants::PERMISSION_GCM_INTENTS} permission.
  4. The BroadcastReceiver(s) handles the 3 GCM intents ({ GCMConstants::INTENT_FROM_GCM_MESSAGE}, { GCMConstants::INTENT_FROM_GCM_REGISTRATION_CALLBACK}, and { GCMConstants::INTENT_FROM_GCM_LIBRARY_RETRY}).

...where

PACKAGE_NAME

is the application package.

This method should be used during development time to verify that the manifest is properly set up, but it doesn't need to be called once the application is deployed to the users' devices.

Parameters
contextapplication context.
Exceptions
IllegalStateExceptionif any of the conditions above is not met.
static long unicopa.copa.app.gcm.GCMRegistrar.getRegisterOnServerLifespan ( Context  context)
static

Gets how long (in milliseconds) the isRegistered(Context) property is valid.

Returns
value set by setRegisteredOnServer(Context, boolean) or DEFAULT_ON_SERVER_LIFESPAN_MS if not set.
static String unicopa.copa.app.gcm.GCMRegistrar.getRegistrationId ( Context  context)
static

Gets the current registration id for application on GCM service.

If result is empty, the registration has failed.

Returns
registration id, or empty string if the registration is not complete.
static boolean unicopa.copa.app.gcm.GCMRegistrar.isRegisteredOnServer ( Context  context)
static

Checks whether the device was successfully registered in the server side, as set by setRegisteredOnServer(Context, boolean).

To avoid the scenario where the device sends the registration to the server but the server loses it, this flag has an expiration date, which is DEFAULT_ON_SERVER_LIFESPAN_MS by default (but can be changed by setRegisterOnServerLifespan(Context, long)).

static synchronized void unicopa.copa.app.gcm.GCMRegistrar.onDestroy ( Context  context)
static

Clear internal resources.

This method should be called by the main activity's

method.

static void unicopa.copa.app.gcm.GCMRegistrar.register ( Context  context,
String...  senderIds 
)
static

Initiate messaging registration for the current application.

The result will be returned as an GCMConstants#INTENT_FROM_GCM_REGISTRATION_CALLBACK intent with either a GCMConstants#EXTRA_REGISTRATION_ID or GCMConstants#EXTRA_ERROR.

Parameters
contextapplication context.
senderIdsGoogle Project ID of the accounts authorized to send messages to this application.
Exceptions
IllegalStateExceptionif device does not have all GCM dependencies installed.
static void unicopa.copa.app.gcm.GCMRegistrar.unregister ( Context  context)
static

Unregister the application.

The result will be returned as an GCMConstants#INTENT_FROM_GCM_REGISTRATION_CALLBACK intent with an GCMConstants#EXTRA_UNREGISTERED extra.

Member Data Documentation

final long unicopa.copa.app.gcm.GCMRegistrar.DEFAULT_ON_SERVER_LIFESPAN_MS
static
Initial value:
=
1000 * 3600 * 24 * 7

Default lifespan (7 days) of the isRegisteredOnServer(Context) flag until it is considered expired.


The documentation for this class was generated from the following file: