Parse push message push learning notes (Android message push solution alternative)

Source: Internet
Author: User

Effect:



Message push may be used in Android development. Today we are learning the parse message push solution.


The official website of parse push. Click here
Https://www.parse.com/


1. Create an application. Registration is required. After registration, follow the prompts to give you the ID and key. My registration is complete. You have created an app.

You can also click here to download the SDK to the libs folder of your Android app.
Parselib. Jar


2. Follow the tutorial. Add the corresponding code as above.

 Parse.initialize(this, "your application id", "your client key");

3. androidmainfest. xml settingsSet 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" />

Add service information:

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

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 obtain the push data from getintent. For example:
B) This code can also be placed in the application and placed behind parse. initialize.

5. Other precautions.

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 a successful sending,
Soon after.
B) note that you must enable client push in the push notifications in the background settings and set it to on.

As shown in.
C). parse push supports iOS and Android Notification Services.

Some of my code (you need to replace the key and ID of your app, which only takes effect for my app.

Parse.initialize(this, "n3GGDen4sv03LFrIp9iM4fxhnwaWh6v2iRt5o8B2", "WP1tIRg40Wi2XRHjCVw1dIOwPkaMHuIELFGY6DrD");
All maninactivity test code is as follows:
package com.lxd.parsepurse.ui;import android.app.Activity;import android.os.Bundle;import com.parse.Parse;import com.parse.ParseAnalytics;import com.parse.ParseObject;import com.parse.PushService;public class MainActivity extends Activity{/** * from : t.qq.com/lixiaodaoaaaa ***** weibo.com/lixiaodaoaaa test by : * lixiaodaoaaa */@Overridepublic void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Parse.initialize(this, "n3GGDen4sv03LFrIp9iM4fxhnwaWh6v2iRt5o8B2", "WP1tIRg40Wi2XRHjCVw1dIOwPkaMHuIELFGY6DrD");ParseAnalytics.trackAppOpened(getIntent());Test();getPush();}private void getPush(){PushService.subscribe(this, "", MainActivity.class);PushService.setDefaultPushCallback(this, MainActivity.class);}private void Test(){ParseObject testObject = new ParseObject("TestObject");testObject.put("foo", "lixiaodaoaaa is a good boyd");testObject.saveInBackground();}}

The test results are as follows:

Related Article

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.