今天主要写了一个小demo来集成极光推送的功能到项目
第一步,先看proj_gradle配置:
buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.2.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files //添加内容 // classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6' } } // this script was used to upload files to bintray. //apply from: 'bintray.gradle' allprojects { repositories { jcenter() } } task clean(type: Delete) { delete rootProject.buildDir }主要添加
// NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files //添加内容 // classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2.再看app.gradle配置
android { compileSdkVersion 23 buildToolsVersion "24.0.2" defaultConfig { applicationId "com.example.maguitao.demo" minSdkVersion 21 targetSdkVersion 23 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" ndk { //选择要添加的对应cpu类型的.so库 abiFilters 'armeabi', 'armeabi-v7a', 'armeabi-v8a' //还可以添加 'armeabi-v7a', 'x86' } manifestPlaceholders = [ JPUSH_PKGNAME : "com.example.maguitao.demo",//包名字 JPUSH_APPKEY : "9389b8bad8346cece74fb112", //JPush上注册的包名对应的appkey. JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可. ] } } 添加依赖compile 'cn.jiguang.sdk:jpush:3.0.0' // 此处以JPush 3.0.0 版本为例。 compile 'cn.jiguang.sdk:jcore:1.0.0' // 此处以JCore 1.0.0 版本为例。
,最后就是清单文件的配置了:<!-- 以下是极光推送的配置--> <!-- Required SDK 核心功能--> <!-- 可配置android:process参数将PushService放在其他进程中 --> <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> <!-- since 1.8.0 option 可选项。用于同一设备中不同应用的JPush服务相互拉起的功能。 --> <!-- 若不启用该功能可删除该组件,将不拉起其他应用也不能被其他应用拉起 --> <service android:name="cn.jpush.android.service.DaemonService" android:enabled="true" android:exported="true"> <intent-filter > <action android:name="cn.jpush.android.intent.DaemonService" /> <category android:name="com.example.maguitao.demo"/> </intent-filter> </service> <!-- Required SDK核心功能--> <receiver android:name="cn.jpush.android.service.PushReceiver" android:enabled="true" > <intent-filter android:priority="1000"> <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY" /> <category android:name="com.example.maguitao.demo"/> </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核心功能--> <activity android:name="cn.jpush.android.ui.PushActivity" android:configChanges="orientation|keyboardHidden" android:theme="@android:style/Theme.NoTitleBar" android:exported="false" > <intent-filter> <action android:name="cn.jpush.android.ui.PushActivity" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="com.example.maguitao.demo" /> </intent-filter> </activity> <!-- Required SDK核心功能--> <service android:name="cn.jpush.android.service.DownloadService" android:enabled="true" android:exported="false" > </service> <!-- Required SDK核心功能--> <receiver android:name="cn.jpush.android.service.AlarmReceiver" /> <!-- User defined. For test only 用户自定义的广播接收器--> <receiver android:name="brodcast.MyReceiver" android:exported="false" android:enabled="true"> <intent-filter> <action android:name="cn.jpush.android.intent.REGISTRATION" /> <!--Required 用户注册SDK的intent--> <action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED" /> <!--Required 用户接收SDK消息的intent--> <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED" /> <!--Required 用户接收SDK通知栏信息的intent--> <action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" /> <!--Required 用户打开自定义通知栏的intent--> <action android:name="cn.jpush.android.intent.CONNECTION" /><!-- 接收网络变化 连接/断开 since 1.6.3 --> <category android:name="com.example.maguitao.demo" /> </intent-filter> </receiver> <!-- Required. For publish channel feature --> <!-- JPUSH_CHANNEL 是为了方便开发者统计APK分发渠道。--> <!-- 例如: --> <!-- 发到 Google Play 的APK可以设置为 google-play; --> <!-- 发到其他市场的 APK 可以设置为 xxx-market。 --> <!-- 目前这个渠道统计功能的报表还未开放。--> <meta-data android:name="JPUSH_CHANNEL" android:value="developer-default"/> <!-- Required. AppKey copied from Portal --> <meta-data android:name="JPUSH_APPKEY" android:value="9389b8bad8346cece74fb112"/> <!-- 极光推送配置完成-->
,,然后就是java代码里面自己初始化private void initJiguang() { JPushInterface.setDebugMode(true); JPushInterface.init(this); }到此完成
demo的下载地址在我个人分享里面:极光推送和环信智能机器人.ZIP