Communication between the Android client and the PHP server (v) --- porting Aurora push, android Server

Source: Internet
Author: User
Tags php server

Communication between the Android client and the PHP server (v) --- porting Aurora push, android Server

Overview

The previous section describes the framework of the sample project. This section describes how to create your own project and port Aurora to it.

Create a project

First, create a project named lovelife and package named com. lygk. lovelife.

Keep "Next" until Finish. The project is created, as shown in figure


Integrate JPush SDK

1. Import the SDK

For details about how to integrate the SDK, see the official JPush documentation.

Http://docs.jpush.io/guideline/android_guide/, here I will briefly describe the steps.



First copy the armeabi folder, armeabi-v7a folder, and jpush-sdk-release1.7.3.jar copy under the sample project shown to your own project libs \ Folder




Right-click the project F5 or project name and select "Refresh" to Refresh. You can see that the project contains the SDK we copied.


2. Configure AndroidManifest. xml

First, add a permission statement.

Note that the content in the red line box corresponds to the Package name of the application you created. My Package is com. lygk. lovelife.

Then configure the application. First, add the Application name, that is, the area in red box. MainApplication is the name of the application to be created.


Then add the PushActivity declaration in the JPush SDK. Note that the section in the red line box corresponds to the package name you created.



Then add the Service declaration


Then, add the Explorer Service declaration. Note that the Section circled by the Red Line corresponds to the package name you created.


Then declare the APPKEY


You may find that there are still some configuration files that are not added. It's okay to start with the simplest process of porting. It is enough to transplant them first.

Create MainApplication class

Create a MainApplication class under src \ Your package \, which inherits the Application

The content of MainApplication. java is as follows:

Package com. lygk. lovelife; import android. app. application; import android. util. log; import cn. jpush. android. api. JPushInterface; public class MainApplication extends Application {private static final String TAG = "LYGK"; @ Override public void onCreate () {Log. d (TAG, "Application startup"); super. onCreate (); JPushInterface. setDebugMode (true); // set to enable logging. Disable JPushInterface when publishing logs. init (this); // initialize JPush }}

After the above Code is added, you can directly debug the real machine. The following Logcat shows that the defined Application has been run.


In this case, if you directly use the console on JPush to send a notification message, the Application can "ding" to receive the notification, but an error message will appear on the mobile phone.

The onResume () function is not added to MainActivity. Next let's modify MainActivity.

Modify MainActivity

The MainActivity generated when a new project is created inherits from the Activity, as shown in figure


Now, modify the parent class to inherit the InstrumentedActivity in the JPush library, as shown in


At the same time, the onResume (), onPause (), and onDestroy () Functions of the parent class are reconstructed.

Run the modified program, as shown in figure


Send push notifications through the console


At this time, the mobile phone can receive the push notification, which means that the minimum system we have migrated is successful.


For this part of code, if necessary, please Click here to download
End

In the above example, I simplified the code in the official routine and transplanted the most basic receiving function. This is a Hello World for JPush, the rest depends on the reader to go to the official documentation, for example, click the notification bar, but return to the main interface? How to display custom messages.

The three short days of May Day are coming to an end. I have also gained new knowledge in these three days. I feel very full and I am not prepared to write it for the moment. I should go out and play the ball, take a bath and sleep comfortably. (The next section describes how to use the PHP server Aurora push interface)
/*************************************** **************************************** ****************

* Original article, reproduced please note the URL: http://blog.csdn.net/mybelief321/article/details/45459705

* Luyang Gaoke Studio

* Address: www.bigbearking.com

* QQ For Business Cooperation: 1519190237

* Business model: website construction, desktop software development, Android/IOS development, image post-processing, and PCB design

**************************************** **************************************** ***************/

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.