android jpush json,Android中接入极光推送

Android中接入极光推送的步骤大体如下:

1.在主module的build.gradle中添加:

android {

defaultConfig {

manifestPlaceholders = [

// app包名

JPUSH_PKGNAME: "com.jiguang.test",

// JPush上注册的包名对应的appkey

JPUSH_APPKEY : "898f0d6299c1666751ca40a1",

// 道通,暂时填写默认值即可

JPUSH_CHANNEL: "developer-default",

]

}

}

dependencies {

......

implementation 'cn.jiguang.sdk:jpush:3.5.8'

implementation 'cn.jiguang.sdk:jcore:2.3.0'

......

}

2.在主module的AndroidManifest.xml中添加:

3.自定义JCommonService类:

package com.jiguang.test.service;

import cn.jpush.android.service.JCommonService;

/**

* 极光推送服务

*/

public class JPushService extends JCommonService {

// 空实现即可

}

4.自定义JPushMessageReceiver类:

package com.jiguang.test.receiver;

import android.content.Context;

import android.text.TextUtils;

import android.util.Base64;

import android.util.Log;

import com.haier.uhome.uplustv.data.JPushBean;

import com.haier.uhome.uplustv.util.RemindUtil;

import com.haier.uhome.uplustv.util.UIUtil;

import org.json.JSONException;

import org.json.JSONObject;

import cn.jpush.android.api.CustomMessage;

import cn.jpush.android.api.NotificationMessage;

import cn.jpush.android.service.JPushMessageReceiver;

/**

* 极光推送的广播接收器

*/

public class JPushReceiver extends JPushMessageReceiver {

private static final String TAG = JPushReceiver.class.getSimpleName();

public JPushReceiver() {

}

/**

* 自定义消息接收

*

* @param context 上下文

* @param customMessage 自定义消息

*/

@Override

public void onMessage(Context context, CustomMessage customMessage) {

Log.d(TAG, "onMessage customMessage=" + customMessage);

}

/**

* 通知消息接收

*

* @param context 上下文

* @param notificationMessage 通知消息

*/

@Override

public void onNotifyMessageArrived(Context context, NotificationMessage notificationMessage) {

Log.d(TAG, "onNotifyMessageArrived notificationMessage=" + notificationMessage);

}

/**

* 点击通知消息

*

* @param context 上下文

* @param notificationMessage 通知消息

*/

@Override

public void onNotifyMessageOpened(Context context, NotificationMessage notificationMessage) {

Log.d(TAG, "onNotifyMessageOpened notificationMessage=" + notificationMessage);

}

/**

* 清除通知消息

*

* @param context 上下文

* @param notificationMessage 通知消息

*/

@Override

public void onNotifyMessageDismiss(Context context, NotificationMessage notificationMessage) {

Log.d(TAG, "onNotifyMessageDismiss notificationMessage=" + notificationMessage);

}

/**

* 注册成功

*

* @param context 上下文

* @param registrationId 注册id

*/

@Override

public void onRegister(Context context, String registrationId) {

Log.d(TAG, "onRegister registrationId=" + registrationId);

}

/**

* 长连接状态变化

*

* @param context 上下文

* @param isConnected 长连接状态,true表示已连接

*/

@Override

public void onConnected(Context context, boolean isConnected) {

Log.d(TAG, "onConnected isConnected=" + isConnected);

}

}

5.在主module的Application类的onCreate方法中添加:

JPushInterface.setDebugMode(true); // debug开关,传true是打开debug模式

JPushInterface.init(this);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值