极光推送jcenter 自动集成

来源:互联网 发布:基址寄存器存数据 编辑:程序博客网 时间:2024/06/06 01:01
一,本来做极光推送我一直习惯性的复制粘贴导入,这一次也这样做了,我搭档不答应了,一脸的不愿意,让我很尴尬;我说我看看官方文档改吧,他说不用了,以后注意点;    然后我就写了个demo,jcenter自动集成。1.首先按文档的来, 确认android studio的 Project 根目录的主 gradle 中配置了jcenter支持。(新建project默认配置就支持,我看了看Studio,默认都有的,这一步可以忽略。)buildscript {repositories {jcenter()}......}allprojets {repositories {jcenter()}}2.在 app 的 gradle 中添加依赖和AndroidManifest的替换变量。android {......defaultConfig {applicationId "com.xxx.xxx" //JPush上注册的包名.......ndk {//选择要添加的对应cpu类型的.so库。 abiFilters 'armeabi', 'armeabi-v7a', 'armeabi-v8a' // 还可以添加 'x86', 'x86_64', 'mips', 'mips64'}manifestPlaceholders = [JPUSH_PKGNAME : applicationId,JPUSH_APPKEY : "你的appkey", //JPush上注册的包名对应的appkey.JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可.]......}......}dependencies {......compile 'cn.jiguang.sdk:jpush:3.0.3'  // 此处以JPush 3.0.3 版本为例。compile 'cn.jiguang.sdk:jcore:1.1.1'  // 此处以JCore 1.1.1 版本为例。......}  3.初始化推送     如下; public class app extends Application {@Overridepublic void onCreate() {super.onCreate();JPushInterface.setDebugMode(true);JPushInterface.init(this);}    }二,到这里好像没什么要做的了,把appkey添加上去试一下,成功了;可以收到通知。      AndroidManifest中也没什么要做的 权限啊 什么的都没用上;一脸懵逼,我暂且认为都不需要了吧,如有发现的朋友多多指点啊!      1.到这里接收是能接收到消息了,可是消息在哪呢?我没找到;    我抱着试一试态度,把手动导入的一段代码复制到了清单文件中;然后写了广播类。如下; <receiver            android:name=".MyReceive"            android:enabled="true">            <intent-filter>                <!--Required 用户注册SDK的intent-->                <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 用户打开自定义通知栏的intent-->                <action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" />                <!-- 接收网络变化 连接/断开 since 1.6.3 -->                <action android:name="cn.jpush.android.intent.CONNECTION" />                <category android:name="com.example.yuxuhao.automaticpackagingjpush" />            </intent-filter>        </receiver>2.然后写一个广播类继承,代码如下;该有的都有了,但心里还是有点忐忑,总觉得少点什么;希望大神们补充啊!public class MyReceive extends BroadcastReceiver {private static final String TAG = "MyReceiver";@Overridepublic void onReceive(Context context, Intent intent) {if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {Log.d(TAG, "JPush用户注册成功");} else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {Log.d(TAG, "接受到推送下来的自定义消息");} else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {Log.d(TAG, "接受到推送下来的通知"+"---------"+intent.getExtras().getString(JPushInterface.EXTRA_ALERT));} else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {Log.d(TAG, "用户点击打开了通知");}}        }