Preface
Reasonable Use of the Push Service can greatly improve user activity. This blog "Parse Push Quick Start Guide" only briefly introduces and uses the Parse Push Service, here we will introduce more usage methods and techniques. This series of articles introduces the Push Service in two parts: all users (on) and channel Users (on ).
Statement
You are welcome to repost, but please keep the original source of the article :)
Blog: http://www.cnblogs.com
Farmer's uncle: http://over140.cnblogs.com
Body
I. Series
1.1 [Parse] development notes (1) -- Preparation
1.2 [Parse] development notes (2) -- import Data from Mysql to Parse Data
1.3 [Parse] development notes (3) -- Implement the nearby searching function (LBS)
2. Preparation
2.1 Android Push Notifications on the official website
Https://www.parse.com/tutorials/android-push-notifications
2.2 [Android] Quick Start Guide to Parse Push
Http://www.cnblogs.com/over140/archive/2013/03/19/2968560.html
Iii. Functions
3.1 Preparation
AndroidManifest. xml
<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"/>
<Application
Android: name = "com. nmbb. lol. LOLApplication"
Android: allowBackup = "true"
Android: icon = "@ drawable/app_icon"
Android: label = "@ string/app_name"
Android: theme = "@ style/AppTheme">
<Service android: name = "com. parse. PushService"/>
<Cycler 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>
</Cycler>
<Cycler android: name = ". cycler. ReceiverPush">
<Intent-filter>
<Action android: name = "com. nmbb. lol. push"/>
</Intent-filter>
</Cycler>
</Application>
Code Description:
Note: This is only a code snippet. Add the code snippet to the project and make corresponding adjustments.
A) The permission for android. permission. RECEIVE_BOOT_COMPLETED is not required. You can remove this permission from the BOOT_COMPLETED of ParseBoradcastReceiver, but you may not be able to receive the push after restarting. You need to open it once. (That's what I want! If you can use less than one permission, the message will not be lost and will be received together next time.
B) PushService must be registered; otherwise, it cannot be used.
C) ReceiverPush will be used later. It is mainly used to receive broadcasts and facilitate the processing of pushed data.
Application
@ Override
Public void onCreate (){
Super. onCreate ();
Parse. initialize (this, "Application ID ",
"Client Key ");
// PushService. subscribe (this, "", WebActivity. class );
PushService. setDefaultPushCallback (this, WebActivity. class );
ParseInstallation. getCurrentInstallation (). saveInBackground ();
}
Code Description:
In addition to configuring AndroidManifest. xml, you only need to add these three lines of code in onCreate of Application.
A) Note that the last row seems to have been added with the latest update. Otherwise, Push cannot be received. The intention is to register the row. You can see it in the Installation object in Data Browser.
B) The second setDefaultPushCallback parameter indicates the Activity to be processed when Notifacation is clicked.
3.2 display push information in the form of Notification (Notification in the status bar)
Go to Push Notifications in the Parse background and click Send a push
3.2.1 send messages
By viewing the sending report, we found that only the alert node is included.
3.2.2 send in JSON format
Title and alert correspond to the title and message of the Android Notification object respectively. If the title is not set, the APP name is displayed by default.
Click "Send Notification". If the Notification succeeds, the device receives the Notification.
3.2.3 process Notification Information
When you click the notification in the status bar, it will jump to the Activity specified by setDefaultPushCallback by default. You can parse the Push data from the Intent:
You can obtain the preceding information directly from getIntent (). getStringExtra ("com. parse. Data") and complete the business logic.
3.2 custom push information is received in the background in the form of broadcast (the status bar does not display notifications)
As long as the message is sent in JSON format and does not contain the title and alert nodes, the Notification will not be displayed (you can decompile it to see the StandardPushCallback class). How can you accept the Push data?
3.2.1 register Boradcast and set Intent-filter. The action set here is com. nmbb. lol. push. The Code has been given above.
3.2.2json data:
{"Action": "com. nmbb. lol. push", "url": "http://v.youku.com/player/getRealM3U8/vid/XNTU1NjkzMDAw/type/mp4/v.m3u8 "}
You must include the action and the matched value to receive the push broadcast. Now you can do what you want to do! Post the Boradcast code here:
Public class ReceiverPush extends BroadcastReceiver {
@ Override
Public void onReceive (Context context, Intent intent ){
If (context! = Null & intent! = Null
& "Com. nmbb. lol. push". equals (intent. getAction ())){
Try {
JSONObject json = new JSONObject (intent. getExtras (). getString (
"Com. parse. Data "));
String title = json. optString ("title ");
String message = json. optString ("message ");
String action = json. optString ("action ");
String url = json. optString ("url ");
ToastUtils. showLongToast (message );
} Catch (JSONException e ){
Logger. e (e );
}
}
}
}
3.3 other notes
A) when sending a message, pay attention to the number of recipients in the upper-right corner, indicating the number of users who receive the push.
B). Enable Client push in Settings.
C). Today, I encountered a particularly strange problem. I couldn't receive the push. I don't know if it is related to setting the APP name to Chinese. I deleted it and rebuilt it to get a new English one.
Iv. Articles
Android Push Notifications In Parse: A deep overview