|
|||||||||
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.
The PushService can listen to pushes from two different sources: Google Cloud Messaging (GCM) or
Parse's own push network. Parse will inspect your application's manifest at
runtime and determine which service to use for push. We recommend using GCM for push on devices
that have Google Play Store support. Parse uses its own push network for apps that want to avoid a
dependency on the Google Play Store, and for devices (like Kindles) which do not have Play Store
support.
To configure the PushService for GCM, ensure these permission declarations are present in your
AndroidManifest.xml as children of the <manifest>
element:
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <permission android:name="YOUR_PACKAGE_NAME.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="YOUR_PACKAGE_NAME.permission.C2D_MESSAGE" />Replace YOUR_PACKAGE_NAME in the declarations above with your application's package name. Also, make sure that com.parse.GcmBroadcastReceiver and com.parse.PushService are declared as children of the<application>
element:<service android:name="com.parse.PushService" /> <receiver android:name="com.parse.GcmBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND"> <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <category android:name="YOUR_PACKAGE_NAME" /> </intent-filter> </receiver>Again, replace YOUR_PACKAGE_NAME with your application's package name. To configure the PushService for Parse's push network, ensure these permission declarations are present in your AndroidManifest.xml as children of the<manifest>
element:<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.WAKE_LOCK" />Also, make sure that com.parse.ParseBroadcastReceiver, com.parse.PushService, and com.parse.ParsePushBroadcastReceiver are declared as children of the<application>
element: <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> <receiver android:name="com.parse.ParsePushBroadcastReceiver" android:exported=false> <intent-filter> <action android:name="com.parse.push.intent.RECEIVE" /> <action android:name="com.parse.push.intent.OPEN" /> <action android:name="com.parse.push.intent.DELETE" /> </intent-filter> </receiver> Note that you can configure the push service for both GCM and Parse's network by adding all the declarations above to your application's manifest. In this case, Parse will use GCM on devices with Play Store support and fall back to using Parse's network on devices without Play Store support. If you want to customize the way your app generates Notifications for your pushes, you can register a custom subclass ofParsePushBroadcastReceiver
Once push notifications are configured in the manifest, you can subscribe to a push channel by calling:ParsePush.subscribeInBackground("the_channel_name");When the client receives a push message, a notification will appear in the system tray. When the user taps the notification, it will broadcast the "com.parse.push.intent.OPEN" intent. TheParsePushBroadcastReceiver
listens to this intent to track an app open event and launch the app's launcher activity. To customize this behavior overrideParsePushBroadcastReceiver.onPushOpen(Context, Intent)
.
Field Summary |
---|
Fields inherited from class android.app.Service |
---|
START_CONTINUATION_MASK, START_FLAG_REDELIVERY, START_FLAG_RETRY, START_NOT_STICKY, START_REDELIVER_INTENT, START_STICKY, START_STICKY_COMPATIBILITY |
Fields inherited from interface android.content.ComponentCallbacks2 |
---|
TRIM_MEMORY_BACKGROUND, TRIM_MEMORY_COMPLETE, TRIM_MEMORY_MODERATE, TRIM_MEMORY_RUNNING_CRITICAL, TRIM_MEMORY_RUNNING_LOW, TRIM_MEMORY_RUNNING_MODERATE, TRIM_MEMORY_UI_HIDDEN |
Constructor Summary | |
---|---|
PushService()
Client code should not construct a PushService directly. |
Method Summary | |
---|---|
static Set<String> |
getSubscriptions(Context context)
Deprecated. Subscriptions are stored in the ParseInstallation "channels" field. Use ParseInstallation.getCurrentInstallation().getList<String>("channels") |
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. |
int |
onStartCommand(Intent intent,
int flags,
int startId)
|
static void |
setDefaultPushCallback(Context context,
Class<? extends Activity> cls)
Deprecated. Replaced by ParsePushBroadcastReceiver |
static void |
setDefaultPushCallback(Context context,
Class<? extends Activity> cls,
int icon)
Deprecated. Replaced by ParsePushBroadcastReceiver |
static void |
subscribe(Context context,
String channel,
Class<? extends Activity> cls)
Deprecated. Developers should use ParsePush.subscribeInBackground and ParsePushBroadcastReceiver. |
static void |
subscribe(Context context,
String channel,
Class<? extends Activity> cls,
int icon)
Deprecated. Developers should use ParsePush.subscribeInBackground and ParsePushBroadcastReceiver. |
static void |
unsubscribe(Context context,
String channel)
Deprecated. Developers should use ParsePush.unsubscribeInBackground and ParsePushBroadcastReceiver. |
Methods inherited from class android.app.Service |
---|
dump, getApplication, onConfigurationChanged, onLowMemory, onRebind, onStart, onTaskRemoved, onTrimMemory, onUnbind, startForeground, stopForeground, stopSelf, stopSelf, stopSelfResult |
Methods inherited from class android.content.Context |
---|
getString, getString, getText, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, registerComponentCallbacks, unregisterComponentCallbacks |
Methods inherited from class Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public PushService()
Method Detail |
---|
@Deprecated 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.ParsePush.subscribeInBackground(String)
,
ParsePushBroadcastReceiver
@Deprecated 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.ParsePush.subscribeInBackground(String)
,
ParsePushBroadcastReceiver
@Deprecated public static void unsubscribe(Context context, String channel)
context
- A currently viable Context.channel
- The string defining the channel to unsubscribe from.ParsePush.unsubscribeInBackground(String)
,
ParsePushBroadcastReceiver
@Deprecated 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.ParsePushBroadcastReceiver.getActivity(Context, Intent)
@Deprecated 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.ParsePushBroadcastReceiver.getActivity(Context, Intent)
,
ParsePushBroadcastReceiver.PROPERTY_PUSH_ICON
,
ParsePushBroadcastReceiver.getSmallIconId(Context, Intent)
@Deprecated public static Set<String> getSubscriptions(Context context)
context
- A currently viable Context.
public void onCreate()
onCreate
in class Service
public int onStartCommand(Intent intent, int flags, int startId)
onStartCommand
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 |