极光推送消息的自动集成与手动集成

极光推送官网注册账号并登录, 创建应用,应用名可以任意,但是包名必须和自己的项目包名一样,创建完成后会生成一个AppKey

在 module 的 gradle中添加依赖和AndroidManifest的替换变量。

1.自动集成

项目的build.gradle

[html]  view plain  copy
  1. apply plugin: 'com.android.application'  
  2.   
  3. android {  
  4.     compileSdkVersion 26  
  5.     buildToolsVersion "26.0.1"  
  6.   
  7.     defaultConfig {  
  8.         applicationId "com.example.lianxiday13_zidongjiguang"  
  9.         minSdkVersion 18  
  10.         targetSdkVersion 26  
  11.         versionCode 1  
  12.         versionName "1.0"  
  13.   
  14.        <strong> <span style="color:#6666CC;">ndk {  
  15.             //选择要添加的对应cpu类型的.so库。  
  16.             abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a'  
  17.             // 还可以添加 'x86', 'x86_64', 'mips', 'mips64'  
  18.         }  
  19.   
  20.         manifestPlaceholders = [  
  21.                 JPUSH_PKGNAME : applicationId,  
  22.                 JPUSH_APPKEY : "0f7d5fa2b54bd8153e829be8", //JPush上注册的包名对应的appkey.  
  23.                 JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可.  
  24.         ]</span></strong>  
  25.     }  
  26.     buildTypes {  
  27.         release {  
  28.             minifyEnabled false  
  29.             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'  
  30.         }  
  31.     }  
  32. }  
  33.   
  34. dependencies {  
  35.     compile fileTree(dir: 'libs', include: ['*.jar'])  
  36.     testCompile 'junit:junit:4.12'  
  37.     compile 'com.android.support:appcompat-v7:26.+'  
  38.   
  39.    <strong><span style="color:#CC33CC;"> compile 'cn.jiguang.sdk:jpush:3.0.9'  // 此处以JPush 3.0.9 版本为例。  
  40.     compile 'cn.jiguang.sdk:jcore:1.1.7'  // 此处以JCore 1.1.7 版本为例。</span></strong>  
  41. }  

自定义类继承Application

[html]  view plain  copy
  1. public class MyApplication extends Application{  
  2.     @Override  
  3.     public void onCreate() {  
  4.         super.onCreate();  
  5.         JPushInterface.setDebugMode(true);  
  6.         JPushInterface.init(this);  
  7.     }  
  8. }  
清单文件中调用name

[html]  view plain  copy
  1. <application  
  2.        android:name="MyApplication"  
[html]  view plain  copy
  1. </application>  


2.手动集成步骤

  • 解压缩 jpush-android--3.x.x-release.zip 集成压缩包。
  • 复制 libs/jcore-android-1.x.x.jar 到工程 libs/ 目录下。
  • 复制 libs/jpush-android-3.x.x.jar 到工程 libs/ 目录下。
  • 复制 libs/(cpu-type)/libjcore1xy.so 到你的工程中存放对应cpu类型的目录下。
  • 复制 res/ 中drawable-hdpi, layout, values文件夹中的资源文件到你的工程中 res/ 对应同名的目录下。


项目的build.gradle

[html]  view plain  copy
  1. apply plugin: 'com.android.application'  
  2.   
  3. android {  
  4.     compileSdkVersion 26  
  5.     buildToolsVersion "26.0.1"  
  6.   
  7.     defaultConfig {  
  8.         applicationId "com.example.wanghuantao171114_day13"  
  9.         minSdkVersion 18  
  10.         targetSdkVersion 26  
  11.         versionCode 1  
  12.         versionName "1.0"  
  13.     }  
  14.     buildTypes {  
  15.         release {  
  16.             minifyEnabled false  
  17.             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'  
  18.         }  
  19.     }  
  20.   
  21.    <strong><span style="color:#9999FF;"> sourceSets {  
  22.         main {  
  23.             jniLibs.srcDirs = ['libs']  
  24.   
  25.         }  
  26.   
  27.     }</span></strong>  
  28. }  
  29.   
  30. dependencies {  
  31.     compile fileTree(dir: 'libs', include: ['*.jar'])  
  32.     testCompile 'junit:junit:4.12'  
  33.     compile 'com.android.support:appcompat-v7:26.+'  
  34. }  

自己写一个类继承Application

[html]  view plain  copy
  1. public class ExampleApplication extends Application{  
  2.     @Override  
  3.     public void onCreate() {  
  4.         super.onCreate();  
  5.         JPushInterface.setDebugMode(true);  
  6.         JPushInterface.init(this);  
  7.     }  
  8. }  


清单文件中配置

根据 SDK 压缩包里的 AndroidManifest.xml 样例文件,来配置应用程序项目的 AndroidManifest.xml 。

主要步骤为:

  • 复制备注为 "Required" 的部分
  • 将标注为“您应用的包名”的部分,替换为当前应用程序的包名
  • 将标注为“您应用的Appkey”的部分,替换为在Portal上注册该应用的的Key,例如:9fed5bcb7b9b87413678c407

[html]  view plain  copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     package="com.example.wanghuantao171114_day13"  
  4.     <span style="color:#3333FF;"><strong>android:versionCode="309"  
  5.     android:versionName="3.0.9"</strong></span>  
  6.     >  
  7.   
  8.    <span style="color:#6666CC;"><strong> <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="21" />  
  9.     <!-- Required -->  
  10.     <permission  
  11.         android:name="com.example.wanghuantao171114_day13.permission.JPUSH_MESSAGE"  
  12.         android:protectionLevel="signature" />  
  13.   
  14.     <!-- Required  一些系统要求的权限,如访问网络等-->  
  15.     <uses-permission android:name="com.example.wanghuantao171114_day13.permission.JPUSH_MESSAGE" />  
  16.     <uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" />  
  17.     <uses-permission android:name="android.permission.INTERNET" />  
  18.     <uses-permission android:name="android.permission.WAKE_LOCK" />  
  19.     <uses-permission android:name="android.permission.READ_PHONE_STATE" />  
  20.     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />  
  21.     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />  
  22.     <uses-permission android:name="android.permission.WRITE_SETTINGS" />  
  23.     <uses-permission android:name="android.permission.VIBRATE" />  
  24.     <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />  
  25.     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />  
  26.     <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />  
  27.   
  28.     <!-- Optional for location -->  
  29.     <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> <!-- 用于开启 debug 版本的应用在6.0 系统上 层叠窗口权限 -->  
  30.     <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />  
  31.     <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />  
  32.     <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />  
  33.     <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />  
  34.     <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />  
  35.     <uses-permission android:name="android.permission.GET_TASKS" /></strong></span>  
  36.   
  37.   
  38.     <application  
  39.        <span style="color:#6666CC;"> android:name="ExampleApplication"</span>  
  40.         android:allowBackup="true"  
  41.         android:icon="@mipmap/ic_launcher"  
  42.         android:label="@string/app_name"  
  43.         android:supportsRtl="true"  
  44.         android:theme="@style/AppTheme">  
  45.         <activity android:name=".MainActivity">  
  46.             <intent-filter>  
  47.                 <action android:name="android.intent.action.MAIN" />  
  48.   
  49.                 <category android:name="android.intent.category.LAUNCHER" />  
  50.             </intent-filter>  
  51.         </activity>  
  52.   
  53.     <strong><span style="color:#6633FF;"><!--    <!– For test only 测试高级功能 –>  
  54.         <activity android:name="com.example.jpushdemo.PushSetActivity" android:label="@string/app_name"></activity>  
  55.         <!– For test only 测试设置 –>  
  56.         <activity android:name="com.example.jpushdemo.SettingActivity" android:label="@string/app_name"></activity>  
  57.         <!– For test only 测试状态通知栏,需要打开的Activity –>  
  58.         <activity android:name="com.example.jpushdemo.TestActivity" android:exported="false">  
  59.             <intent-filter>  
  60.                 <action android:name="jpush.testAction" />  
  61.                 <category android:name="jpush.testCategory" />  
  62.             </intent-filter>  
  63.         </activity>-->  
  64.   
  65.         <!-- Rich push 核心功能 since 2.0.6-->  
  66.         <activity  
  67.             android:name="cn.jpush.android.ui.PopWinActivity"  
  68.             android:theme="@style/MyDialogStyle"  
  69.             android:exported="false">  
  70.         </activity>  
  71.   
  72.         <!-- Required SDK核心功能-->  
  73.         <activity  
  74.             android:name="cn.jpush.android.ui.PushActivity"  
  75.             android:configChanges="orientation|keyboardHidden"  
  76.             android:theme="@android:style/Theme.NoTitleBar"  
  77.             android:exported="false">  
  78.             <intent-filter>  
  79.                 <action android:name="cn.jpush.android.ui.PushActivity" />  
  80.                 <category android:name="android.intent.category.DEFAULT" />  
  81.                 <category android:name="com.example.wanghuantao171114_day13" />  
  82.             </intent-filter>  
  83.         </activity>  
  84.   
  85.         <!-- Required SDK 核心功能-->  
  86.         <!-- 可配置android:process参数将PushService放在其他进程中 -->  
  87.         <service  
  88.             android:name="cn.jpush.android.service.PushService"  
  89.             android:process=":mult"  
  90.             android:exported="false">  
  91.             <intent-filter>  
  92.                 <action android:name="cn.jpush.android.intent.REGISTER" />  
  93.                 <action android:name="cn.jpush.android.intent.REPORT" />  
  94.                 <action android:name="cn.jpush.android.intent.PushService" />  
  95.                 <action android:name="cn.jpush.android.intent.PUSH_TIME" />  
  96.             </intent-filter>  
  97.         </service>  
  98.         <!-- since 3.0.9 Required SDK 核心功能-->  
  99.         <provider  
  100.             android:authorities="com.example.wanghuantao171114_day13.DataProvider"  
  101.             android:name="cn.jpush.android.service.DataProvider"  
  102.             android:exported="true"  
  103.             />  
  104.   
  105.         <!-- since 1.8.0 option 可选项。用于同一设备中不同应用的JPush服务相互拉起的功能。 -->  
  106.         <!-- 若不启用该功能可删除该组件,将不拉起其他应用也不能被其他应用拉起 -->  
  107.         <service  
  108.             android:name="cn.jpush.android.service.DaemonService"  
  109.             android:enabled="true"  
  110.             android:exported="true">  
  111.             <intent-filter>  
  112.                 <action android:name="cn.jpush.android.intent.DaemonService" />  
  113.                 <category android:name="com.example.wanghuantao171114_day13" />  
  114.             </intent-filter>  
  115.   
  116.         </service>  
  117.   
  118.         <!-- Required SDK核心功能-->  
  119.         <receiver  
  120.             android:name="cn.jpush.android.service.PushReceiver"  
  121.             android:enabled="true"  
  122.             android:exported="false">  
  123.             <intent-filter android:priority="1000">  
  124.                 <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY" />   <!--Required  显示通知栏 -->  
  125.                 <category android:name="com.example.wanghuantao171114_day13" />  
  126.             </intent-filter>  
  127.             <intent-filter>  
  128.                 <action android:name="android.intent.action.USER_PRESENT" />  
  129.                 <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />  
  130.             </intent-filter>  
  131.             <!-- Optional -->  
  132.             <intent-filter>  
  133.                 <action android:name="android.intent.action.PACKAGE_ADDED" />  
  134.                 <action android:name="android.intent.action.PACKAGE_REMOVED" />  
  135.   
  136.                 <data android:scheme="package" />  
  137.             </intent-filter>  
  138.         </receiver>  
  139.   
  140.         <!-- Required SDK核心功能-->  
  141.         <receiver android:name="cn.jpush.android.service.AlarmReceiver" android:exported="false"/>  
  142.   
  143.         <!-- User defined.  For test only  用户自定义的广播接收器  
  144.         <receiver  
  145.             android:name="com.example.jpushdemo.MyReceiver"  
  146.             android:exported="false"  
  147.             android:enabled="true">  
  148.             <intent-filter>  
  149.                 <action android:name="cn.jpush.android.intent.REGISTRATION" /> <!–Required  用户注册SDK的intent–>  
  150.                 <action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED" /> <!–Required  用户接收SDK消息的intent–>  
  151.                 <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED" /> <!–Required  用户接收SDK通知栏信息的intent–>  
  152.                 <action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" /> <!–Required  用户打开自定义通知栏的intent–>  
  153.                 <action android:name="cn.jpush.android.intent.CONNECTION" /><!– 接收网络变化 连接/断开 since 1.6.3 –>  
  154.                 <category android:name="您应用的包名" />  
  155.             </intent-filter>  
  156.         </receiver>-->  
  157.   
  158.         <!-- User defined.  For test only  用户自定义接收消息器,3.0.7开始支持,目前新tag/alias接口设置结果会在该广播接收器对应的方法中回调-->  
  159.         <!--<receiver android:name="com.example.jpushdemo.MyJPushMessageReceiver">  
  160.             <intent-filter>  
  161.                 <action android:name="cn.jpush.android.intent.RECEIVE_MESSAGE" />  
  162.                 <category android:name="您应用的包名"></category>  
  163.             </intent-filter>  
  164.         </receiver>-->  
  165.         <!-- Required  . Enable it you can get statistics data with channel -->  
  166.         <meta-data android:name="JPUSH_CHANNEL" android:value="developer-default"/>  
  167.         <meta-data android:name="JPUSH_APPKEY" android:value="92b5743e9710d1c61a334507" /> <!--  </>值来自开发者平台取得的AppKey--></span></strong>  
  168.   
  169.     </application>  
  170.   
  171. </manifest>  

在极光potal页面上 推送内容
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值