Overview
The previous section examined the framework of the example project, which prepares itself to create the project and migrate the aurora to it.
Create a project
First create a project, the project name and the application name Lovelife, the package name Com.lygk.lovelife
Always "Next" until finish, at which time the building works are completed, such as
Integrated Jpush SDK
1. Import SDK Development Package
For an integrated SDK approach, Jpush official documentation has been described in detail and can be viewed
http://docs.jpush.io/guideline/android_guide/, here I briefly describe the steps.
First copy the Armeabi folder, armeabi-v7a folder, Jpush-sdk-release1.7.3.jar copy under the example project shown below to the project Libs\ folder you created.
Then in the project F5 or the project name right click to select "Refresh" refreshed, you can see that the project now contains the SDK we copied.
2. Configure Androidmanifest.xml
First, add a permission declaration
Note that the contents of the Red Line box correspond to the package name of the app you created, and mine is Com.lygk.lovelife.
Then configure application, first add the app name, that is, the Red Line box out of the section, where MainApplication is the name I am about to create application.
Then add the Pushactivity declaration in the Jpush SDK and note that the Red Line box is the part that corresponds to the package name you created.
Then add the service services statement
Then add the Receiver Service statement, note that the red line circled out of the section corresponding to the package name you created.
Then declare Appkey
You may find that there are still some configuration file content is not added, no matter, porting from the simplest to start, first porting these is enough.
Creating the MainApplication Class
Create a new class MainApplication under Src\your package\, which inherits application
Mainapplication.java content 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 Start"); Super.oncreate (); Jpushinterface.setdebugmode (TRUE); Set open log, close log jpushinterface.init (this) when publishing; Initialize Jpush }}
After adding the code as above, you can directly debug the real machine, the following logcat can see the definition of application has been running
At this time if you directly with the Jpush on the console to send a notification message, at this time application can "ding" received the push notification, but at this time the phone will appear error prompt
This means that there is no onresume () function added to the mainactivity. Let's change mainactivity.
Modify Mainactivity
The mainactivity generated when the new project is created inherits from activity, such as
Now, to modify its parent class so that it inherits the instrumentedactivity in the Jpush library, such as
Also, refactor the parent class's Onresume (), OnPause (), OnDestroy () function.
At this point, run the modified program, such as
Send push notifications through the console
At this point, you can receive push notifications on your phone, which means that the smallest system we have migrated is successful.
For this part of the code, if necessary, please
Click here to download
End
In the example above, I streamlined the official routines in the code, porting the most basic receive function, this is a Hello world about Jpush, the rest of the reader to see the official documents to explore, such as click on the notification bar, but back to the main interface? How to display a custom message and so on.
51 Short three days is coming to an end, this three days I also get new knowledge, feel pretty substantial, temporarily not ready to write, should go out to play ball, wash a bath comfortable sleep. (The next section prepares to write the use of the PHP service-side Aurora push interface)
/***********************************************************************************************
* Luyang High Tech Studio
* Website: www.bigbearking.com
* Business Cooperation qq:1519190237
* Business Scope: Website construction, desktop software development, Android\ios development, image and film post-processing, PCB design
***********************************************************************************************/