[Android] Quick Start Guide to Parse Push

Source: Internet
Author: User

Preface

We have long known about the Parse service, which is designed to provide server support for developers. In addition, we launched the Push Service, which is just intended to be used. It is fast, simple, and easy to use in practice. Here we record our usage experiences.

 

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. Preparation

For more information about Parse, see the link at the end of this article (1 million free Push messages per month ). First, you need to create a Parse account, create an application, download the SDK, decompress the SDK, and copy the jar to the libs directory.

Official Website: Parse Push

You can try this download link: Parse-1.2.0.zip

 

2. Call Parse. initialize in the onCreate method of your Application class, as shown below:

Import android. app. Application;
Import com. parse. Parse;
 
Public class MyApplication extends Application {
 
Public void onCreate (){
Parse. initialize (this, "your application id", "your client key ");
}
 
}

After logging on to and creating the application, click Quickstart at the top of the page to enter the English version of this article. You have already filled in the applicationid and key and copied them directly to the program.

 

3. AndroidMainfest. xml settings

Set permissions, broadcast, and Service.

<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"/>

 

<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>

Do not add any errors.

 

4. subscribe to Push notifications

PushService. subscribe (this, "", YourActivity. class );
PushService. setDefaultPushCallback (this, YourActivity. class );

Note:

A) The last parameter YourActivity. class is the Activity that receives and processes messages when you click push messages on the taskbar. You can get the push data from getIntent. For example:

Com. parse. Channel: null

Com. parse. Data: {"alert": "test", "push_hash": "098f6bcd4621d373cade4e832627b4f6 "}

B) the code can also be placed in the Application and placed behind Parse. initialize.

C) receive JSON data in the form of broadcast:

Public class MyCustomReceiver extends BroadcastReceiver {
Private static final String TAG = "MyCustomReceiver ";

@ Override
Public void onReceive (Context context, Intent intent ){
Try {
String action = intent. getAction ();
String channel = intent. getExtras (). getString ("com. parse. Channel ");
JSONObject json = new JSONObject (intent. getExtras (). getString ("com. parse. Data "));

Log. d (TAG, "got action" + action + "on channel" + channel + ":");
Iterator itr = json. keys ();
While (itr. hasNext ()){
String key = (String) itr. next ();
Log. d (TAG, "..." + key + "=>" + json. getString (key ));
}
} Catch (JSONException e ){
Log. d (TAG, "JSONException:" + e. getMessage ());
}
}
}

 

V. Others

A ). during the test, it was found that, according to the quick development documentation, it was useless to click Send Temp Push at the end, but thought it failed. directly go to Push Notifications in the application background and click Send a push, then you can send the message. After the message is sent successfully once, it will soon be followed.

B) note that you must enable Client Push in the push notifications in the background Settings and set it to ON.

C). Parse Push supports IOS and Android Notification Services.

D) It seems that the Code will be updated after 1.3)

ParseInstallation. getCurrentInstallation (). saveInBackground ();

 

 

6. Related Articles

Android push implementation solution

Parse is a well-developed backend platform designed for your IOS and Android applications.

Auxiliary services for mobile application development

 

End

We originally planned to try Aurora push. Here we will try Parse first. There are a lot of startups engaged in apps now. In fact, this kind of developer service is also very good, so it is easier to make profits and ultimately serve customers. What is the purpose of entrepreneurship?

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.