Communication between the Android client and the PHP Server (IV)-Aurora push example project analysis-php Tutorial

Source: Internet
Author: User
Tags php server
Communication between the Android client and the PHP Server (IV)-Aurora push example project analysis Overview

The previous section describes how to register Aurora push and use its example. this section is about to study the framework of the sample project to prepare for porting it.

Analysis routine source code

First analyze the source code structure of the routine, it is recommended to compare the official document JPUSH (http://docs.jpush.io/) analysis, I am doing this.

After the application is registered, the following sample project structure is downloaded,



ExampleApplication. java: This class customizes an Application class for the Application. when calling the JPush SDK, you need to call the init () function API provided by JPush, according to the instructions in the official document, "init only needs to call this API once when the Application starts." Therefore, an Application class is customized. if you call init () in MainActivity (), it may cause multiple calls to init. Of course, the defined ExampleApplication class must be configured in AndoridManifest. xml.

ExampleUtil. java: As the name suggests, "Util" indicates some global methods or attributes. some static functions are defined in this class, such as getting IME codes and APPKEY.

MainActivity. java: this is the main interface of the application.

MyReceiver. java: This inherits from BroadcastReceiver and is a custom receiver inheritance class. If this class is not defined, the user clicks push notification and jumps to the main interface by default, and cannot receive custom messages. This class also needs to be configured in AndoridManifest. xml, as shown in.



PushSetActivity. java: This class mainly sets "Advanced options" for JPush, such as setting tags and Alias, and customizing the notification bar style.

SettingActivity. java: This class also sets JPush, mainly to set the receiving push time.

TestActivity. java: This class inherits the Activity and is mainly used to display the push messages received by the user. when the user clicks the push message in the notification bar, the Activity will jump.


Next we will analyze AndoridManifest. xml to make the content complete.


Row 2: specify the Android namespace

Row 3: specifies the standard application package name, which is also the default name of an application. The package name may be confused by comparing it with the com. example. jpushdemo package in the src folder. Actually, I know more about android professional development. a src can contain multiple custom packages. this com. example. the jpush package only includes some call operations for JPush. if you are familiar with JPush in the future, you can completely extract the JPush operations and encapsulate them in a custom package.

Row 4: ID of the application version of the device. it must be an integer that indicates the number of times that the app has been updated. you can customize it when you modify it to yourself.

Row 5: for users to view the version, it must be readable.

Row 7: specifies the SDK version to be used in the application, such as the minimum version, maximum version, and target version.

Row 8-10: custom user permissions. Note that android: name = "com. lygk. lovelife. permission. JPUSH_MESSAGE ", if your JPush package name is com. test. jpushdemo. here is android: name = "com. test. jpushdemo. JPUSH_MESSAGE ", in fact, this is not true, just a name, as long as the name used in other places that reference this permission is consistent with this, for example, the custom permission is declared in line 13.

Row 13-33: permission statement required by the application, which can be found in the official documentation.

Row 34-139: configuration root element of the application, which contains all configuration elements related to the application.

Row 35: application icon

Row 36: Application Name

Row 37: this is the name of the Applicatioin class defined by us, that is, the ExampleApplication under the com. example. jpushdemo package started by the application.

Line 40-47: Activity component (Interface Controller component) declaration, corresponding to MainActivity. java. Note that every Activity in the Android application must be declared in the AndoridManifest. xml configuration file. Otherwise, the system will not recognize or execute the Activity.

Row 49: Activity component declaration, corresponding to PushSetActivity. java

Row 51: Activity component declaration, corresponding to SettingActivity. java

Row 53-58: Activity component declaration, corresponding to TestActivity. java

Row 62-71: Activity component declaration, which corresponds to PushActivity. java defined in the JPush SDK package. I suspect this is the Activity displayed in the notification bar when the mobile phone receives the push message.

Line 7-77: The Declaration label of the Service component, used to define and describe a specific Android Service. Android: name indicates the Service class name, android: enabled indicates the Service switch, and android: exported indicates whether the Service can be called or interacted with other application components.

Line 1-92: The PushService service declaration defined in the JPush SDK package.

Line 95-113: Boardcast Receiver component declaration, used to define and describe a specific Android broadcast Receiver. Android: name indicates the name of the Boardcast Receiver class, and android: enabled indicates the Receiver switch. Note that Declaration used for Intent message filter. Must contain elements, that is, the name used to describe a specific message; Tags are used to indicate the category of the message component that can be processed, that is, the category that the Action conforms.

Row 3: Declaration of the Boardcast Receiver broadcast Receiver component. here is the AlarmReceiver.

Row 119-132: Boardcast Receiver broadcast Receiver component Declaration. here is the custom broadcast Receiver of MyReceiver, which corresponds to MyReceiver. java of the source package.

Row 3: Label JPUSH_CHANNEL declaration, Used to store pre-defined data, and Similarly, It can also be placed in ,, And Of the four element labels. Meta data usually appears in the form of key-value pairs, and there is no limit on the number, and the data will be put into a Bundle object, in the program, we can use the metaData attribute of the ActivityInfo, ServiceInfo, or even ApplicationInfo object to read.

Row 3: The label JPUSH_APPKEY is declared. this is the AppKey allocated by the system when you create an application on the Aurora push official website, as shown in the red line.



End

I analyzed the framework of sample code automatically generated when I created an application on the Aurora push official website. after this analysis, I generally know how to port the sample code to my application, in the next section, I plan to modify and port it to my Demo program.

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

* 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

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

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.