Android client server to communicate with PHP (five) --- transplant using push Aurora

Outline

    Prepare a study on the framework of an example project, this section ready to create their own works, and Aurora transplanted to push it on.

Create Project

    First, create a project, the project name and application name is lovelife, the package name com.lygk.lovelife

    Has been "Next", until Finish, this time to establish the project is completed, as shown below


Integrated JPush SDK

1. Import developer SDK

    About SDK integrated approach, JPush official document has been very detailed, you can go

http://docs.jpush.io/guideline/android_guide/, here I describe a simple procedure.



    First armeabi file in the example shown above project folder, armeabi-v7a folder, jpush-sdk-release1.7.3.jar copy copy to create their own project libs \ folder




    Then in the project in F5 or right-click on the project name to select "Refresh" to refresh, you can see at this time we project already contains a copy of the SDK.


2. Configure AndroidManifest.xml

    First, add a permission notice

    Note that the red line out of the box corresponding to the contents Package package name of the application you created, I was com.lygk.lovelife.

    Then configure the application, the application must first add the name of that red box out of the lower part of the chart, which is MainApplication Application name I am going to be created.


    Then add PushActivity statement JPush SDK in, note that the red box out of the portion corresponding to the package name you have created.



    Then add Service Service Statement


    Then add Receiver service announcements, pay attention to the red portion of the coil corresponding to the package name you created.


    Then declare APPKEY


    you may find that there are some elements of the configuration file is not marked, all right, transplanted from the most simple to start, first transplant them enough.

Create a class MainApplication

    MainApplication create a new class in src \ Your package \ under, it inherited Application

    MainApplication.java reads 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启动");
        super.onCreate();

        JPushInterface.setDebugMode(true); 	// 设置开启日志,发布时请关闭日志
        JPushInterface.init(this);     		// 初始化 JPush
    }
}

    After adding the above code can debug a real machine directly, it can be seen as defined Logcat Application already running


    At this point, if you send a notification message directly on the console JPush, Application at this time may have been "bite" to receive notification push, but an error message appears on the phone

    Meaning that there is no added onResume () function in MainActivity in. Here we go modify MainActivity.

Modify MainActivity

    Generated when the newly created project MainActivity inherited from the Activity, as shown below


    Now, to modify the parent class, it inherits JPush library InstrumentedActivity, below


    the same time, the reconstructed onResume parent class (), onPause (), onDestroy () function.

    In this case, the program run the modified, as FIG.


    By console, send push notifications


    At this point you can receive push notifications on your phone, so we explain the most minimal system transplant be successful.


    On this part of the code, if necessary, please click here to download
the end

    In the above example, I streamlined the official routines in the code, porting the most basic reception, which can be considered a Hello World JPush about it, and the rest by the reader to see the official document explored, such as clicking the notification bar , but returned to the main interface? How to display custom messages, and so on.

    Fifty-one short three days coming to an end, three days and I get new knowledge, I feel pretty substantial, not yet ready to write, which go around playing baseball, bath comfortable night's sleep the. (The next section ready to write PHP server-side push to use Aurora interface)
/ ********************************** ************************************************** ***********

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

* Lu Yang Tech Studios

* Website: www.bigbearking.com

* Business cooperation QQ: 1519190237

Scope of service: construction sites, desktop software development, Android \ IOS development, film and television post-image processing, PCB design

***********************************************************************************************/
Published 143 original articles · won praise 161 · Views 1.21 million +

Guess you like

Origin blog.csdn.net/mybelief321/article/details/45459705