package com.hanju.video.app.util;
|
|
import android.content.Context;
|
import android.content.Intent;
|
import android.content.SharedPreferences;
|
import android.util.Log;
|
|
import com.lcjian.library.util.common.PackageUtils2;
|
import com.lcjian.library.util.common.StringUtils;
|
import com.tencent.android.tpush.XGIOperateCallback;
|
import com.tencent.android.tpush.XGPushBaseReceiver;
|
import com.tencent.android.tpush.XGPushConfig;
|
import com.tencent.android.tpush.XGPushManager;
|
import com.tencent.android.tpush.XGPushShowedResult;
|
import com.tencent.android.tpush.service.XGPushService;
|
|
/**
|
* Created by weikou2015 on 2016/9/8.
|
*/
|
public class XGPush {
|
|
public static void registerPush(Context context) {
|
// 开启logcat输出,方便debug,发布时请关闭
|
XGPushConfig.enableDebug(context, true);
|
// 如果需要知道注册是否成功,请使用registerPush(getApplicationContext(), XGIOperateCallback)带callback版本
|
// 如果需要绑定账号,请使用registerPush(getApplicationContext(),account)版本
|
// 具体可参考详细的开发指南
|
// 传递的参数为ApplicationContext
|
SharedPreferences sp = context.getSharedPreferences("user", Context.MODE_PRIVATE);
|
String loginId = sp.getString("LoginUid", "");
|
XGPushManager.setTag(context, PackageUtils2.getVersionCode(context) + "_A");
|
if (StringUtils.isEmpty(loginId)) {
|
XGPushManager.registerPush(context, new XGIOperateCallback() {
|
@Override
|
public void onSuccess(Object o, int i) {
|
}
|
|
@Override
|
public void onFail(Object o, int i, String s) {
|
}
|
});
|
} else {
|
XGPushManager.registerPush(context, loginId, new XGIOperateCallback() {
|
@Override
|
public void onSuccess(Object o, int i) {
|
}
|
|
@Override
|
public void onFail(Object o, int i, String s) {
|
}
|
});
|
|
}
|
// // 2.36(不包括)之前的版本需要调用以下2行代码
|
// Intent service = new Intent(context, XGPushService.class);
|
// context.startService(service);
|
|
// 其它常用的API:
|
// 绑定账号(别名)注册:registerPush(context,account)或registerPush(context,account, XGIOperateCallback),其中account为APP账号,可以为任意字符串(qq、openid或任意第三方),业务方一定要注意终端与后台保持一致。
|
// 取消绑定账号(别名):registerPush(context,"*"),即account="*"为取消绑定,解绑后,该针对该账号的推送将失效
|
// 反注册(不再接收消息):unregisterPush(context)
|
// 设置标签:setTag(context, tagName)
|
// 删除标签:deleteTag(context, tagName)
|
}
|
|
public static void unRegisterPush(Context context) {
|
XGPushManager.unregisterPush(context);
|
}
|
|
}
|