Android message Push SDK integration Guide

Source: Internet
Author: User
<span id="Label3"></p>Tips for using<p><p>This article is an integrated guidance document for the Android SDK Standard.</p></p><p><p>The matching SDK versions are: r1.8.0 and later Versions.</p></p><p><p>This article is distributed with the SDK compression Package. When you see this article, it is possible that the current version is not well-suited to this article. therefore, It is recommended to follow online documentation:</p></p> <ul> <ul> <li>3-minute Quick Demo (Android): If you want to quickly test and feel the effects of the Aurora push, please refer to this article for a few minutes to run through the demo.</li> <li>On the Aurora push document website, There are all the guides, apis, tutorials, and all the other documents related to Aurora Push. Include an updated version of this document, which will be posted to the site in a timely manner.</li> <li>Aurora Push Quiz Website: Everyone in addition to the document, there are questions and questions, will come here to ask questions, in time to get Answers.</li> <li>If you see this document but have not yet downloaded the Android sdk, please visit the SDK download page for Download.</li> </ul> </ul>Product function Description<p><p>Aurora Push (jpush) is an end-to-end push service that enables server-side messages to be pushed to end-user phones in a timely manner, allowing developers to actively stay connected to users, increasing user activity and increasing the retention rate of applications. Aurora Push Client supports Android, IOS two platforms.</p></p><p><p>The Android SDK makes it easy for developers to add push functionality to Android apps quickly based on Jpush.</p></p>Key Features <ul> <ul> <li>Maintain a long connection to the server so that messages can be pushed to the client immediately</li> <li>Receive notifications and custom messages and deliver relevant information to the developer app</li> </ul> </ul>Key Features <ul> <ul> <li>Client-side connection consumes less resources and consumes low power</li> <li>SDK Rich interface, customizable notification bar tip style</li> <li>Server Large capacity, Stable</li> </ul> </ul>Jpush-sdk_v1.x.y.zip Integrated Compressed Package content <ul> <ul> <li>Andoridmanifest.xml <ul> <li>Client-side Embedding SDK Reference configuration file</li> </ul></li> <li>Libs/jpush-sdk-release1.x.y.jar <ul> <li>SDK Java Development Kit</li> </ul></li> <li>Libs/armeabi/libjpush.so <ul> <li>SDK Native Development Kit</li> </ul></li> <li>Res <ul> <li>Resource files that the Integration SDK must add</li> </ul></li> <li>Example <ul> <li>is a complete Android project, which demonstrates the basic usage of the Jpush SDK and can be used as a reference.</li> </ul></li> </ul> </ul>Android SDK Version<p><p>currently, the SDK only supports Android 2.1 or later mobile phone Systems. The rich media information flow feature is required for Android3.0 or above versions of the System.</p></p>SDK Integration Step 1, Import SDK Development package to your own application project <ul> <ul> <li>Decompression Jpush-sdk_v1.x.y.zip Integrated Compression package</li> <li>Copy Libs/jpush-sdk-release1.x.y.jar to the project Libs/directory</li> <li>Copy libs/armeabi/libjpush1xy.so to the project Libs/armeabi directory</li> <li>Copy libs/armeabi-v7a/libjpush.so to the project libs/armeabi-v7a directory</li> </ul> </ul><p style="padding-bottom: 0; margin-bottom: 0;"><p style="padding-bottom: 0; margin-bottom: 0;">If your project has libs/armeabi-v7a this directory, please copy the so file under libs/armeabi-v7a to this directory as Well.</p></p> <ul> <ul> <li>Copy the resource files in the res/drawable-hdpi into the res/drawable-hdpi/directory of the project</li> <li>Copy the layout file in Res/layout to the res/layout/directory of the project</li> </ul> </ul>2, Configuration Androidmanifest.xml<p><p>Configure the Androidmanifest.xml of the application project according to the Androidmanifest.xml sample file in the SDK compression package.</p></p><p><p>The main steps are:</p></p> <ul> <ul> <li>Copy the section with notes as "Required"</li> <li>Replace the comment as part of the replacement package name with the current Application's package name</li> <li>Replace the Appkey with the key that registered the app on the portal, for example (9fed5bcb7b9b87413678c407)</li> </ul> </ul><pre class="prettyprint well"><code><span class="typ">Androidmanifest<span class="pun">.<span class="pln">Xml<span class="pun">Permissions Configuration:<span class="pln"><span class="pun"><?<span class="pln">XML version<span class="pun">=<span class="str">"1.0"<span class="pln">Encoding<span class="pun">=<span class="str">"utf-8"<span class="pun">?><span class="pln"><span class="pun"><<span class="pln">Manifest xmlns<span class="pun">:<span class="pln">Android<span class="pun">=<span class="str">"http://schemas.android.com/apk/res/android"<span class="pln"> <span class="kwd">Package<span class="pun">=<span class="str">"Your package"<span class="pln">Android<span class="pun">:<span class="pln">Versioncode<span class="pun">=<span class="str">"100"<span class="pln">Android<span class="pun">:<span class="pln">Versionname<span class="pun">=<span class="str">"1.0.0"<span class="pln"> <span class="pun">><span class="pln"> <span class="pun"><<span class="pln">Uses<span class="pun">-<span class="pln">SDK Android<span class="pun">:<span class="pln">Minsdkversion<span class="pun">=<span class="str">"11"<span class="pln">Android<span class="pun">:<span class="pln">Targetsdkversion<span class="pun">=<span class="str">"17"<span class="pln"> <span class="pun">/><span class="pln"> <span class="pun"><!--<span class="pln"> <span class="typ">Required<span class="pln"> <span class="pun">-<span class="pln"> <span class="pun"><<span class="pln">Permission Android<span class="pun">:<span class="pln">Name<span class="pun">=<span class="str">"Your Package.permission.JPUSH_MESSAGE"<span class="pln">Android<span class="pun">:<span class="pln">ProtectionLevel<span class="pun">=<span class="str">"signature"<span class="pln"> <span class="pun">/><span class="pln"> <span class="pun"><!--<span class="pln"> <span class="typ">Required<span class="pln"> <span class="pun">-<span class="pln"> <span class="pun"><<span class="pln">Uses<span class="pun">-<span class="pln">Permission Android<span class="pun">:<span class="pln">Name<span class="pun">=<span class="str">"you Package.permission.JPUSH_MESSAGE"<span class="pln"> <span class="pun">/><span class="pln"> <span class="pun"><<span class="pln">Uses<span class="pun">-<span class="pln">Permission Android<span class="pun">:<span class="pln">Name<span class="pun">=<span class="str">"android.permission.RECEIVE_USER_PRESENT"<span class="pln"> <span class="pun">/><span class="pln"> <span class="pun"><<span class="pln">Uses<span class="pun">-<span class="pln">Permission Android<span class="pun">:<span class="pln">Name<span class="pun">=<span class="str">"android.permission.INTERNET"<span class="pln"> <span class="pun">/><span class="pln"> <span class="pun"><<span class="pln">Uses<span class="pun">-<span class="pln">Permission Android<span class="pun">:<span class="pln">Name<span class="pun">=<span class="str">"android.permission.WAKE_LOCK"<span class="pln"> <span class="pun">/><span class="pln"> <span class="pun"><<span class="pln">Uses<span class="pun">-<span class="pln">Permission Android<span class="pun">:<span class="pln">Name<span class="pun">=<span class="str">"android.permission.READ_PHONE_STATE"<span class="pln"> <span class="pun">/><span class="pln"> <span class="pun"><<span class="pln">Uses<span class="pun">-<span class="pln">Permission Android<span class="pun">:<span class="pln">Name<span class="pun">=<span class="str">"android.permission.WRITE_EXTERNAL_STORAGE"<span class="pln"> <span class="pun">/><span class="pln"> <span class="pun"><<span class="pln">Uses<span class="pun">-<span class="pln">Permission Android<span class="pun">:<span class="pln">Name<span class="pun">=<span class="str">"android.permission.READ_EXTERNAL_STORAGE"<span class="pln"> <span class="pun">/><span class="pln"> <span class="pun"><<span class="pln">Uses<span class="pun">-<span class="pln">Permission Android<span class="pun">:<span class="pln">Name<span class="pun">=<span class="str">"android.permission.VIBRATE"<span class="pln"> <span class="pun">/><span class="pln"> <span class="pun"><<span class="pln">Uses<span class="pun">-<span class="pln">Permission Android<span class="pun">:<span class="pln">Name<span class="pun">=<span class="str">"android.permission.MOUNT_UNMOUNT_FILESYSTEMS"<span class="pln"> <span class="pun">/><span class="pln"> <span class="pun"><<span class="pln">Uses<span class="pun">-<span class="pln">Permission Android<span class="pun">:<span class="pln">Name<span class="pun">=<span class="str">"android.permission.ACCESS_NETWORK_STATE"<span class="pln"> <span class="pun">/><span class="pln"> <span class="pun"><<span class="pln">Uses<span class="pun">-<span class="pln">Permission Android<span class="pun">:<span class="pln">Name<span class="pun">=<span class="str">"android.permission.WRITE_SETTINGS"<span class="pln"> /> <!--Optional. Required for location feature--<uses-permission android:name= "android.permission.ACCESS_COARSE_LOCATION"/ > <uses-permission android:name= "android.permission.ACCESS_WIFI_STATE"/> <uses-permission android:name = "android.permission.CHANGE_WIFI_STATE"/> <uses-permission android:name= "android.permission.ACCESS_FINE_ Location "/> <uses-permission android:name=" Android.permission.ACCESS_LOCATION_EXTRA_COMMANDS "/> < Uses-permission android:name= "android.permission.CHANGE_NETWORK_STATE"/> App package name and Appkey replacement: <application Android : icon= "@drawable/ic_launcher" android:label= "@string/app_name" android:name= "Your application" > <!--Required --<service android:name= "cn.jpush.android.service.PushService" android:enabled= "true" android:exported= " False "> <intent-filter> <action android:name=" Cn.jpush.android.intent.REGISTER "/> <action Android : Name= "cn.jpush.android.intent.REPORT"/> <action android:Name= "cn.jpush.android.intent.PushService"/> <action android:name= "cn.jpush.android.intent.PUSH_TIME"/> </intent-filter> </service> <!--Required SDK core features-<!--since 1.8.0-<service Android:na Me= "cn.jpush.android.service.DaemonService" android:enabled= "true" android:exported= "true" > <intent-filter > <action android:name= "cn.jpush.android.intent.DaemonService"/> <category android:name= "Your package"/ > </intent-filter> </service> <!--Required--<receiver android:name= " Cn.jpush.android.service.PushReceiver "android:enabled=" true "> <intent-filter android:priority=" + "> <action android:name= "cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY"/> <category android:name= " Your Package "/> </intent-filter> <intent-filter> <action android:name=" Android.intent.action.USER _present "/> <action android:name=" Android.net.conn.CONNECTIVITY_CHANGE "/> </intent-filter> <!--Optional-<intent-filter> <action android:name= "android.intent.action.PACKAGE_ADDED"/ > <action android:name= "android.intent.action.PACKAGE_REMOVED"/> <data android:scheme= "package"/> </intent-filter> </receiver> <!--Required SDK core functions--<activity android:name= " Cn.jpush.android.ui.PushActivity "android:configchanges=" Orientation|keyboardhidden "android:exported=" false " > <intent-filter> <action android:name= "cn.jpush.android.ui.PushActivity"/> <category android: Name= "android.intent.category.DEFAULT"/> <category android:name= "Your package"/> </intent-filter> </activity> <!--Required SDK Core Functions--<service android:name= "cn.jpush.android.service.DownloadService "android:enabled=" true "android:exported=" false "> </service> <!--Required SDK Core Features--<receiver Android:name= "cn.jpush.android.service.AlarmReceiver"/> <!--User Defined. User-defined Broadcast receivers--<receiver android:name= "your own definition of receiver" android:enabled= "true" > <intent-filter> <!--Required User Registration SDK intent--> <action android:name= "cn.jpush.android.intent.REGISTRATION"/> <action android:name= " Cn.jpush.android.intent.UNREGISTRATION "/> <!--Required user receives intent--> <action android:name= for SDK messages" Cn.jpush.android.intent.MESSAGE_RECEIVED "/> <!--Required user receives intent--> <action android:name= of SDK notification bar information Cn.jpush.android.intent.NOTIFICATION_RECEIVED "/> <!--Required users to open the custom notification bar intent--> <action android: Name= "cn.jpush.android.intent.NOTIFICATION_OPENED"/> <!--Optional User accepts the intent--> of the rich Push Javascript callback function <action android:name= "cn.jpush.android.intent.ACTION_RICHPUSH_CALLBACK"/> <!--receive network changes connect/disconnect since 1.6.3-- > <action android:name= "cn.jpush.android.intent.CONNECTION"/> <category android:name= "package name you apply"/> < /intent-filter> </receiver> <!--Required. For publish channel feature---<! --jpush_channel is designed to facilitate developers to count APK distribution Channels. -<!--for example:-<!--to Google Play apk can be set to google-play; -<!--to Other markets APK can be set to Xxx-market. -<!--the Current report on this channel stats feature is not yet Open. --<meta-data android:name= "jpush_channel" android:value= "developer-default"/> <!--Required. AppKey copied from Portal to <meta-data android:name= "jpush_appkey" android:value= "Your AppKey"/> </ Application></manifest></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></code></pre>3, must have permission to explain <table style="width: 100%;" border="1"> <tbody> <tr bgcolor="#D3D3D3"> <th style="padding: 0 5px;">Permissions</th> <th style="padding: 0 5px;">Use</th> </tr> <tr> <td style="padding: 0 5px;">You Package.permission.JPUSH_MESSAGE</td> <td style="padding: 0 5px;">An officially defined permission that allows the app to receive broadcast messages sent by Jpush internal Code.</td> </tr> <tr> <td style="padding: 0 5px;">Receive_user_present</td> <td style="padding: 0 5px;">Allows an app to receive a lit screen or unlock a broadcast.</td> </tr> <tr> <td style="padding: 0 5px;">INTERNET</td> <td style="padding: 0 5px;">Allows the app to access the Network.</td> </tr> <tr> <td style="padding: 0 5px;">Wake_lock</td> <td style="padding: 0 5px;">Allows the app to still run after the phone screen shuts down after the background process</td> </tr> <tr> <td style="padding: 0 5px;">Read_phone_state</td> <td style="padding: 0 5px;">Allows the app to access the Phone's Status.</td> </tr> <tr> <td style="padding: 0 5px;">Write_external_storage</td> <td style="padding: 0 5px;">Allows an app to write to external storage.</td> </tr> <tr> <td style="padding: 0 5px;">Read_external_storage</td> <td style="padding: 0 5px;">Allows an app to read external Storage.</td> </tr> <tr> <td style="padding: 0 5px;">Write_settings</td> <td style="padding: 0 5px;">Allows the app to read and write system settings.</td> </tr> <tr> <td style="padding: 0 5px;">Vibrate</td> <td style="padding: 0 5px;">Allows vibration to be applied.</td> </tr> <tr> <td style="padding: 0 5px;">Mount_unmount_filesystems</td> <td style="padding: 0 5px;">Allows the app to mount/unload external file Systems.</td> </tr> <tr> <td style="padding: 0 5px;">Access_network_state</td> <td style="padding: 0 5px;">Allows the app to get the status of the network information, such as whether the current network connection is VALID.</td> </tr> <tr> <td style="padding: 0 5px;">System_alert_window</td> <td style="padding: 0 5px;">Allows the app to display the system window at the top level of the Display.</td> </tr> </tbody> </table>4. Add code<p><p>The API interfaces provided by the Jpush SDK are mainly concentrated in the Cn.jpush.android.api.JPushInterface class.</p></p>Base API <ul> <ul> <li><p>Init Initialization SDK</p><pre class="prettyprint well"><code><span class="kwd">public<span class="pln"> <span class="kwd">static<span class="pln"> <span class="kwd">void<span class="pln"> init<span class="pun">(<span class="typ">Context<span class="pln"> context<span class="pun">)</span></span></span></span></span></span></span></span></span></span></code></pre></li> <li><p>Setdebugmode Setting debug mode</p><pre class="prettyprint well"><code><span class="com">// You can enable debug mode in developing state. You should close debug mode when release.<span class="pln"><span class="kwd">public<span class="pln"> <span class="kwd">static<span class="pln"> <span class="kwd">void<span class="pln"> setDebugMode<span class="pun">(<span class="kwd">boolean<span class="pln"> debugEnalbed<span class="pun">)</span></span></span></span></span></span></span></span></span></span></span></span></code></pre></li> </ul> </ul>Add Statistics Code <ul> <ul> <li>Reference Documentation: statistical analysis API</li> </ul> </ul>Invoking the sample code (refer to Example Project) <ul> <li><li><p>Init only needs to invoke the API once when the application Starts.</p></li></li> <li><p><p>The following code customizes a application class of this Application. Need to be configured in Andoridmanifest.xml. Please refer to the above Androidmanifest.xml fragment, or example Project.</p></p><pre class="prettyprint well"><code><span class="kwd">Public<span class="pln"> <span class="kwd">Class<span class="pln"> <span class="typ">Exampleapplication<span class="pln"> <span class="kwd">Extends<span class="pln"> <span class="typ">Application<span class="pln"><span class="pln"> <span class="pun">{<span class="pln"><span class="lit"> @Override <span class="pln"> <span class="pln" public<span> <span class="kwd">void<span class="pln"> Oncreate<span class="pun"> () <span class="pun" <span>{<span class="pln"> <span class="kwd">super<span class="pun">.<span class="typ" oncreate<span (); <span>jpushinterface<span class="pun">.<span class="kwd" setdebugmode<span (<span>true<span class="typ" ); <span>jpushinterface<span class="pun">.<span class="kwd" init<span (<span>this<span class="pun" ); <span>}<span class="pln"><span class="pun">} </span> </span> </span> </span> </span> </span> </span> </span> </span> /span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span></span></span></span></span></span></span></span></span></span></code></pre></li> </ul>5. Test Confirmation <ol> <ol> <li>Verify that the required permissions have been Added. If the required permissions are not added, the log will prompt for Errors.</li> <li>Verify that the AppKey (generated on the Portal) has been correctly written to Androidmanifest.xml.</li> <li>Confirm that the Init (context) interface is called when the program starts</li> <li>Confirm that the test phone (or Emulator) has successfully connected to the Network + client after calling init, if everything is ok, log information should be logged in successfully</li> <li>Launches the application and sends a custom <span style="font-family: 黑体;"><strong>message push</strong></span> or notification bar prompt to the application on the Portal. Please refer to manage portal for Details. <ul> <li>In a few seconds, the client should be able to receive a notification or a positive definition message if the SDK works correctly, the log information will look like the following:</li> </ul></li> </ol> </ol><p><p></p></p><p><p>, the client boot is divided into 4 steps:</p></p> <ol> <ol> <li>Check the AppKey and channel of the metadata and fail to start if it does not exist</li> <li>Initializes the Jpush SDK to check the validity of library files such as JNI and fails to start if the library file is invalid</li> <li>Check Androidmanifest.xml if the Required permission does not exist, the startup fails</li> <li>Connection Server login, If there is a network problem, the login failed, or the previous three steps have a problem, will not start the Jpush SDK</li> </ol> </ol>Import from Eclipse Engineering to Android Studio<p><p>The Jpush demo is an example of the usage of the Aurora push with the compression pack, which was originally intended for Eclipse Engineering. This tutorial will instruct Jpush users to import the Aurora push demo into Android Studio in the simplest way.</p></p>6.1 Fast Integration Jpush<p><p>Refer to the 3-minute quick Demo (Android) to run the Jpush. You will then have a running project in the Eclipse package Browser.</p></p><p><p></p></p>6.2 Right click on demo project, Select Export<p><p></p></p>6.3 Select the export target bit gradle build file and confirm<p><p></p></p>6.4 Checking from the file browser<p><p>In Eclipse's workspace, the Gradle related profile is generated in the demo Project's Folder.</p></p><p><p></p></p>6.5 Open your Android studio project and select File->import Module<p><p>In Android studio, you can only open one project at a time, which is equivalent to a workspace in Eclipse. A project that we export from eclipse is equivalent to a module in Android Studio.</p></p><p><p></p></p>6.6 Select the Demo project under Eclipse Workspace and confirm<p><p></p></p><p><p></p></p>6.7 View the imported module, and Gradle will automatically generate compilation options<p><p></p></p><p><p></p></p><p><p>The Aurora push demo can now be run on a real or virtual machine as a module of Android studio and debugged</p></p><p><p>Android message Push SDK integration Guide</p></p></span>

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.