java.lang.Object | |
↳ | com.google.android.gcm.GCMRegistrar |
This class is deprecated.
Please use the
GoogleCloudMessaging
API instead.
Utilities for device registration.
Note: this class uses a private SharedPreferences
object to keep track of the registration token.
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
long | DEFAULT_ON_SERVER_LIFESPAN_MS | Default lifespan (7 days) of the isRegisteredOnServer(Context)
flag until it is considered expired. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Checks if the device has the proper dependencies installed.
| |||||||||||
Checks that the application manifest is properly configured.
| |||||||||||
Gets how long (in milliseconds) the
isRegistered(Context)
property is valid. | |||||||||||
Gets the current registration id for application on GCM service.
| |||||||||||
Checks whether the application was successfully registered on GCM
service.
| |||||||||||
Checks whether the device was successfully registered in the server side,
as set by
setRegisteredOnServer(Context, boolean) . | |||||||||||
Clear internal resources.
| |||||||||||
Initiate messaging registration for the current application.
| |||||||||||
Sets how long (in milliseconds) the
isRegistered(Context)
flag is valid. | |||||||||||
Sets whether the device was successfully registered in the server side.
| |||||||||||
Unregister the application.
|
[Expand]
Inherited Methods | |||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Default lifespan (7 days) of the isRegisteredOnServer(Context)
flag until it is considered expired.
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. |
---|
Checks that the application manifest is properly configured.
A proper configuration means:
PACKAGE_NAME.permission.C2D_MESSAGE
.
BroadcastReceiver
with category
PACKAGE_NAME
.
BroadcastReceiver
(s) uses the
com.google.android.gcm.GCMConstants.PERMISSION_GCM_INTENTS
permission.
BroadcastReceiver
(s) handles the 2 GCM intents
(com.google.android.gcm.GCMConstants.INTENT_FROM_GCM_MESSAGE
and
com.google.android.gcm.GCMConstants.INTENT_FROM_GCM_REGISTRATION_CALLBACK
).
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.
context | application context. |
---|
IllegalStateException | if any of the conditions above is not met. |
---|
Gets how long (in milliseconds) the isRegistered(Context)
property is valid.
setRegisteredOnServer(Context, boolean)
or
DEFAULT_ON_SERVER_LIFESPAN_MS
if not set.
Gets the current registration id for application on GCM service.
If result is empty, the registration has failed.
Checks whether the application was successfully registered on GCM service.
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)
).
Clear internal resources.
This method should be called by the main activity's onDestroy()
method.
Initiate messaging registration for the current application.
The result will be returned as an
INTENT_FROM_GCM_REGISTRATION_CALLBACK
intent with
either a EXTRA_REGISTRATION_ID
or
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. |
---|
Sets how long (in milliseconds) the isRegistered(Context)
flag is valid.
Sets whether the device was successfully registered in the server side.
Unregister the application.
The result will be returned as an
INTENT_FROM_GCM_REGISTRATION_CALLBACK
intent with an
EXTRA_UNREGISTERED
extra.