|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.google.android.gcm.GCMRegistrar
public final class GCMRegistrar
Utilities for device registration.
Note: this class uses a private SharedPreferences
object to keep track of the registration token.
Method Summary | |
---|---|
static void |
checkDevice(Context context)
Checks if the device has the proper dependencies installed. |
static void |
checkManifest(Context context)
Checks that the application manifest is properly configured. |
static java.lang.String |
getRegistrationId(Context context)
Gets the current registration id for application on GCM service. |
static boolean |
isRegistered(Context context)
Checks whether the application was successfully registered on GCM service. |
static boolean |
isRegisteredOnServer(Context context)
Checks whether the device was successfully registered in the server side. |
static void |
onDestroy(Context context)
Clear internal resources. |
static void |
register(Context context,
java.lang.String... senderIds)
Initiate messaging registration for the current application. |
static void |
setRegisteredOnServer(Context context,
boolean flag)
Sets whether the device was successfully registered in the server side. |
static void |
unregister(Context context)
Unregister the application. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static void checkDevice(Context context)
This method should be called when the application starts to verify that the device supports GCM.
context
- application context.
java.lang.UnsupportedOperationException
- if the device does not support GCM.public static void checkManifest(Context context)
A proper configuration means:
PACKAGE_NAME.permission.C2D_MESSAGE
.
BroadcastReceiver
with category
PACKAGE_NAME
.
BroadcastReceiver
(s) uses the
permission.
BroadcastReceiver
(s) handles the 3 GCM intents
(,
,
and ).
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.
java.lang.IllegalStateException
- if any of the conditions above is not met.public static void register(Context context, java.lang.String... senderIds)
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.
java.lang.IllegalStateException
- if device does not have all GCM
dependencies installed.public static void unregister(Context context)
The result will be returned as an
GCMConstants.INTENT_FROM_GCM_REGISTRATION_CALLBACK
intent with an
GCMConstants.EXTRA_UNREGISTERED
extra.
public static void onDestroy(Context context)
This method should be called by the main activity's onDestroy()
method.
public static java.lang.String getRegistrationId(Context context)
If result is empty, the registration has failed.
public static boolean isRegistered(Context context)
public static void setRegisteredOnServer(Context context, boolean flag)
public static boolean isRegisteredOnServer(Context context)
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |