Phonegap + Aurora push + page Jump

Source: Internet
Author: User

Recently, the company used sencha touch to develop the app to implement the push function. It took me a week to push Android and iOS pages to jump to the page. There are very few materials to push in the evening, and there are fewer materials to jump to the page after the push, so I am afraid I will forget it here.

First, the implementation method of Android (first, you need to register an account on Aurora push ):

1: Use sencha cmd to create the st application:

sencha -sdk D:\java\sencha-touch\touch-2.3.1 generate app FirstApp ../FirstApp
A standard sencha touch file is generated.

2: Initialize phonegap in the created st folder (the file directory in cmd must be under the folder)

sencha phonegap init com.cloudvast.FirstApp FirstApp
Com. cloudvast. firstapp is very important. This must be consistent with the Android app package name created in Aurora push. Otherwise, errors may occur. After phonegap is initialized, the files in the folder are:



Modify the phonegap. Local. properties file first:




Modify Ios to Android, because the Android app is packaged;


3: Install the plug-in of Aurora push for phonegap, and CD the directory in cmd to the phonegap folder.

phonegap  plugin add https://github.com/jpush/jpush-phonegap-plugin.git
After the installation is successful, an aurora plug-in package will be added:


Open the new file and select the push-sdk-release1.6.1.jar file:



Right click> build path> Add to build path to add to project

Then open the jpus2d-ugin. Java file in the same directory.



Find this line and change com. Thi. pushtest to the package name used to initialize phonegap. After I modify it to: Import com. cloudvast. firstapp. R;. Close the package after saving it.


Find the plug-in. xml file under the plug-in package and open it:



Find this line


In the value field, fill in the appkey we applied for on Aurora push.


So far, the phonegap set Aurora push has been completed, and the push can be used normally after packaging. Next we will implement the page Jump function:


Find the jpushzugin. js file under the plug-in package to open it:


Add a piece of code to the file:

JPushPlugin.prototype.getNotification = function(successCallback, data) {console.log("JPushPlugin:getNotification");try {ret = cordova.exec(successCallback, successCallback, 'JPushPlugin', "getNotification", [data]);return ret;} catch (exception) {alert(exception);}}

Then write the logic code in the app. js file in our sencha touch.


Add code:

Document. addeventlistener ('resume', function () {window. plugins. jpushzugin. getnotification (function (OBJ) {// OBJ ["message"] indicates the received push information if (OBJ ["message"]! = "") {Var extra = obj. extras ['cn. jpush. android. extra ']; extra = extra. replace (// \/g, ""); extra = ext. JSON. decode (extra, true); If (extra. type = "Mode") {Ext. getcmp ('tab '). setactiveitem (1); // If the passed type = 'Mode', it will jump to the second page }}, false );});

Extra is an additional field in the optional settings below when Aurora pushes notifications.



Finally, move the CMD directory to the phonegap directory and perform the packaging operation:

sencha app build native


After packaging, the APK file is generated under the directory:



 






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.