|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Objectandroid.content.Context
android.content.ContextWrapper
android.app.Service
com.parse.PushService
public final class PushService
A service to listen for push notifications. This operates in the same process as the parent
application. To use this class, the PushService must be registered. Add this XML right before the
</application>
tag in your AndroidManifest.xml:
<service android:name="com.parse.PushService" /> <receiver android:name="com.parse.ParseBroadcastReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.USER_PRESENT" /> </intent-filter> </receiver>Next, you must ensure your app has the permissions needed to show a notification. Make sure that these permissions are present in your AndroidManifest.xml, typically immediately before the
</manifest>
tag:
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.VIBRATE" />Once push notifications are configured in the manifest, you can subscribe to a push channel by calling
PushService.subscribe(context, "the_channel_name", YourActivity.class);When the client receives a push message, a notification will appear in the system tray. When the user taps the notification, they will enter the application through a new instance of YourActivity.
Field Summary |
---|
Constructor Summary | |
---|---|
PushService()
Client code should not construct a PushService directly. |
Method Summary | |
---|---|
static Set<String> |
getSubscriptions(Context context)
Accesses the current set of channels for which the current installation is subscribed. |
IBinder |
onBind(Intent intent)
onBind should not be called directly. |
void |
onCreate()
Client code should not call onCreate directly. |
void |
onDestroy()
Client code should not call onDestroy directly. |
static void |
setDefaultPushCallback(Context context,
Class<? extends Activity> cls)
Provides a default Activity class to handle pushes. |
static void |
setDefaultPushCallback(Context context,
Class<? extends Activity> cls,
int icon)
Provides a default Activity class to handle pushes. |
static void |
startServiceIfRequired(Context context)
|
static void |
subscribe(Context context,
String channel,
Class<? extends Activity> cls)
Helper function to subscribe to push notifications with the default application icon. |
static void |
subscribe(Context context,
String channel,
Class<? extends Activity> cls,
int icon)
Call this function when the user should be subscribed to a new push channel. |
static void |
unsubscribe(Context context,
String channel)
Cancels a previous call to subscribe. |
Methods inherited from class android.app.Service |
---|
dump, finalize, getApplication, onConfigurationChanged, onLowMemory, onRebind, onStart, onUnbind, setForeground, stopSelf, stopSelf, stopSelfResult |
Methods inherited from class android.content.Context |
---|
getString, getString, getText, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes |
Methods inherited from class Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public PushService()
Method Detail |
---|
public static void startServiceIfRequired(Context context)
public static void subscribe(Context context, String channel, Class<? extends Activity> cls)
context
- This is used to access local storage to cache the subscription, so it must currently
be a viable context.channel
- A string identifier that determines which messages will cause a push notification to
be sent to this client. The channel name must start with a letter and contain only
letters, numbers, dashes, and underscores.cls
- This should be a subclass of Activity. An instance of this Activity is started when
the user responds to this push notification. If you are not sure what to use here,
just use your application's main Activity subclass.
IllegalArgumentException
- if the channel name is not valid.public static void subscribe(Context context, String channel, Class<? extends Activity> cls, int icon)
context
- This is used to access local storage to cache the subscription, so it must currently
be a viable context.channel
- A string identifier that determines which messages will cause a push notification to
be sent to this client. The channel name must start with a letter and contain only
letters, numbers, dashes, and underscores.cls
- This should be a subclass of Activity. An instance of this Activity is started when
the user responds to this push notification. If you are not sure what to use here,
just use your application's main Activity subclass.icon
- The icon to show for the notification.
IllegalArgumentException
- if the channel name is not valid.public static void unsubscribe(Context context, String channel)
context
- A currently viable Context.channel
- The string defining the channel to unsubscribe from.public static void setDefaultPushCallback(Context context, Class<? extends Activity> cls)
context
- This is used to access local storage to cache the subscription, so it must currently
be a viable context.cls
- This should be a subclass of Activity. An instance of this Activity is started when
the user responds to this push notification. If you are not sure what to use here,
just use your application's main Activity subclass.public static void setDefaultPushCallback(Context context, Class<? extends Activity> cls, int icon)
context
- This is used to access local storage to cache the subscription, so it must currently
be a viable context.cls
- This should be a subclass of Activity. An instance of this Activity is started when
the user responds to this push notification. If you are not sure what to use here,
just use your application's main Activity subclass.icon
- The icon to show for the notification.public static Set<String> getSubscriptions(Context context)
context
- A currently viable Context.
public void onCreate()
onCreate
in class Service
public IBinder onBind(Intent intent)
onBind
in class Service
public void onDestroy()
onDestroy
in class Service
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |