Utilities for device registration. More...
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... | |
Utilities for device registration.
Note: this class uses a private SharedPreferences object to keep track of the registration token.
|
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.
context | application context. |
UnsupportedOperationException | if the device does not support GCM. |
|
static |
Checks that the application manifest is properly configured.
A proper configuration means:
...where
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.
context | application context. |
IllegalStateException | if any of the conditions above is not met. |
|
static |
Gets how long (in milliseconds) the isRegistered(Context) property is valid.
|
static |
Gets the current registration id for application on GCM service.
If result is empty, the registration has failed.
|
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 |
|
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.
context | application context. |
senderIds | Google Project ID of the accounts authorized to send messages to this application. |
IllegalStateException | if device does not have all GCM dependencies installed. |
|
static |
Unregister the application.
The result will be returned as an GCMConstants#INTENT_FROM_GCM_REGISTRATION_CALLBACK intent with an GCMConstants#EXTRA_UNREGISTERED extra.
|
static |
Default lifespan (7 days) of the isRegisteredOnServer(Context) flag until it is considered expired.