version:2.7
fix: update:修改推送,增加视频和日常应用
This commit is contained in:
62
app/src/main/java/com/uiuios/aios/push/PushManager.java
Normal file
62
app/src/main/java/com/uiuios/aios/push/PushManager.java
Normal file
@@ -0,0 +1,62 @@
|
||||
package com.uiuios.aios.push;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.uiuios.aios.config.CommonConfig;
|
||||
import com.uiuios.aios.disklrucache.CacheHelper;
|
||||
import com.uiuios.aios.utils.ToastUtil;
|
||||
|
||||
public class PushManager {
|
||||
private static final String TAG = PushManager.class.getSimpleName();
|
||||
|
||||
public static final String SET_ALARMCLOCK = "zuoyeos.action.change.alarmclaock";
|
||||
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private static PushManager sInstance;
|
||||
private Context mContext;
|
||||
private ContentResolver mResolver;
|
||||
private CacheHelper mCacheHelper;
|
||||
private MMKV mMMKV = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
|
||||
|
||||
private PushManager(Context context) {
|
||||
if (context == null) {
|
||||
throw new RuntimeException("Context is NULL");
|
||||
}
|
||||
this.mContext = context;
|
||||
this.mResolver = context.getContentResolver();
|
||||
this.mCacheHelper = new CacheHelper(context);
|
||||
}
|
||||
|
||||
public static void init(Context context) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new PushManager(context);
|
||||
}
|
||||
}
|
||||
|
||||
public static PushManager getInstance() {
|
||||
if (sInstance == null) {
|
||||
throw new IllegalStateException("You must be init PushManager first");
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
private static final String JIGUANG_ALARM_CLOCK = "57";
|
||||
|
||||
public void setPushContent(String title, String extras) {
|
||||
switch (title) {
|
||||
case JIGUANG_ALARM_CLOCK:
|
||||
ToastUtil.betaShow("收到推送消息: 设置闹钟");
|
||||
Intent intent = new Intent(SET_ALARMCLOCK);
|
||||
mContext.sendBroadcast(intent);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.uiuios.aios.push.alipush;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.alibaba.sdk.android.push.AliyunMessageIntentService;
|
||||
import com.alibaba.sdk.android.push.notification.CPushMessage;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by liyazhou on 17/8/22.
|
||||
* 为避免推送广播被系统拦截的小概率事件,我们推荐用户通过IntentService处理消息互调,接入步骤:
|
||||
* 1. 创建IntentService并继承AliyunMessageIntentService
|
||||
* 2. 覆写相关方法,并在Manifest的注册该Service
|
||||
* 3. 调用接口CloudPushService.setPushIntentService
|
||||
* 详细用户可参考:https://help.aliyun.com/document_detail/30066.html#h2-2-messagereceiver-aliyunmessageintentservice
|
||||
*/
|
||||
|
||||
public class AliMessageIntentService extends AliyunMessageIntentService {
|
||||
private static final String TAG = AliyunMessageIntentService.class.getSimpleName();
|
||||
|
||||
/**
|
||||
* 推送通知的回调方法
|
||||
*
|
||||
* @param context
|
||||
* @param title
|
||||
* @param summary
|
||||
* @param extraMap
|
||||
*/
|
||||
@Override
|
||||
protected void onNotification(Context context, String title, String summary, Map<String, String> extraMap) {
|
||||
Log.i(TAG, "收到一条推送通知 : " + title + ", summary:" + summary);
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送消息的回调方法
|
||||
*
|
||||
* @param context
|
||||
* @param cPushMessage
|
||||
*/
|
||||
@Override
|
||||
protected void onMessage(Context context, CPushMessage cPushMessage) {
|
||||
Log.i(TAG, "收到一条推送消息 : " + cPushMessage.getTitle() + ", content:" + cPushMessage.getContent());
|
||||
}
|
||||
|
||||
/**
|
||||
* 从通知栏打开通知的扩展处理
|
||||
*
|
||||
* @param context
|
||||
* @param title
|
||||
* @param summary
|
||||
* @param extraMap
|
||||
*/
|
||||
@Override
|
||||
protected void onNotificationOpened(Context context, String title, String summary, String extraMap) {
|
||||
Log.i(TAG, "onNotificationOpened : " + " : " + title + " : " + summary + " : " + extraMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 无动作通知点击回调。当在后台或阿里云控制台指定的通知动作为无逻辑跳转时,通知点击回调为onNotificationClickedWithNoAction而不是onNotificationOpened
|
||||
*
|
||||
* @param context
|
||||
* @param title
|
||||
* @param summary
|
||||
* @param extraMap
|
||||
*/
|
||||
@Override
|
||||
protected void onNotificationClickedWithNoAction(Context context, String title, String summary, String extraMap) {
|
||||
Log.i(TAG, "onNotificationClickedWithNoAction : " + " : " + title + " : " + summary + " : " + extraMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通知删除回调
|
||||
*
|
||||
* @param context
|
||||
* @param messageId
|
||||
*/
|
||||
@Override
|
||||
protected void onNotificationRemoved(Context context, String messageId) {
|
||||
Log.i(TAG, "onNotificationRemoved : " + messageId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用处于前台时通知到达回调。注意:该方法仅对自定义样式通知有效,相关详情请参考https://help.aliyun.com/document_detail/30066.html#h3-3-4-basiccustompushnotification-api
|
||||
*
|
||||
* @param context
|
||||
* @param title
|
||||
* @param summary
|
||||
* @param extraMap
|
||||
* @param openType
|
||||
* @param openActivity
|
||||
* @param openUrl
|
||||
*/
|
||||
@Override
|
||||
protected void onNotificationReceivedInApp(Context context, String title, String summary, Map<String, String> extraMap, int openType, String openActivity, String openUrl) {
|
||||
Log.i(TAG, "onNotificationReceivedInApp : " + " : " + title + " : " + summary + " " + extraMap + " : " + openType + " : " + openActivity + " : " + openUrl);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package com.uiuios.aios.push.alipush;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.alibaba.sdk.android.push.MessageReceiver;
|
||||
import com.alibaba.sdk.android.push.notification.CPushMessage;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.uiuios.aios.push.PushManager;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author: 正纬
|
||||
* @since: 15/4/9
|
||||
* @version: 1.1
|
||||
* @feature: 用于接收推送的通知和消息
|
||||
*/
|
||||
public class AliyunMessageReceiver extends MessageReceiver {
|
||||
// 消息接收部分的LOG_TAG
|
||||
public static final String TAG = AliyunMessageReceiver.class.getSimpleName();
|
||||
|
||||
/**
|
||||
* 推送通知的回调方法
|
||||
*
|
||||
* @param context
|
||||
* @param title
|
||||
* @param summary
|
||||
* @param extraMap
|
||||
*/
|
||||
@Override
|
||||
public void onNotification(Context context, String title, String summary, Map<String, String> extraMap) {
|
||||
// TODO 处理推送通知
|
||||
if (null != extraMap) {
|
||||
for (Map.Entry<String, String> entry : extraMap.entrySet()) {
|
||||
Log.i(TAG, "@Get diy param : Key=" + entry.getKey() + " , Value=" + entry.getValue());
|
||||
}
|
||||
} else {
|
||||
Log.i(TAG, "@收到通知 && 自定义消息为空");
|
||||
}
|
||||
Log.i(TAG, "收到一条推送通知 : " + title + ", summary:" + summary);
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用处于前台时通知到达回调。注意:该方法仅对自定义样式通知有效,相关详情请参考https://help.aliyun.com/document_detail/30066.html?spm=5176.product30047.6.620.wjcC87#h3-3-4-basiccustompushnotification-api
|
||||
*
|
||||
* @param context
|
||||
* @param title
|
||||
* @param summary
|
||||
* @param extraMap
|
||||
* @param openType
|
||||
* @param openActivity
|
||||
* @param openUrl
|
||||
*/
|
||||
@Override
|
||||
protected void onNotificationReceivedInApp(Context context, String title, String summary, Map<String, String> extraMap, int openType, String openActivity, String openUrl) {
|
||||
Log.i(TAG, "onNotificationReceivedInApp : " + " : " + title + " : " + summary + " " + extraMap + " : " + openType + " : " + openActivity + " : " + openUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送消息的回调方法
|
||||
*
|
||||
* @param context
|
||||
* @param cPushMessage
|
||||
*/
|
||||
@Override
|
||||
public void onMessage(Context context, CPushMessage cPushMessage) {
|
||||
Log.e(TAG, "收到一条推送消息 : " + cPushMessage.getTitle() + ", content:" + cPushMessage.getContent());
|
||||
String title = cPushMessage.getTitle();
|
||||
String content = cPushMessage.getContent();
|
||||
JsonObject extrasJson = JsonParser.parseString(content).getAsJsonObject();
|
||||
String extras = "";
|
||||
if (extrasJson.get("extras") != null) {
|
||||
extras = extrasJson.get("extras").toString();
|
||||
}
|
||||
PushManager.getInstance().setPushContent(title, extras);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从通知栏打开通知的扩展处理
|
||||
*
|
||||
* @param context
|
||||
* @param title
|
||||
* @param summary
|
||||
* @param extraMap
|
||||
*/
|
||||
@Override
|
||||
public void onNotificationOpened(Context context, String title, String summary, String extraMap) {
|
||||
Log.i(TAG, "onNotificationOpened : " + " : " + title + " : " + summary + " : " + extraMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通知删除回调
|
||||
*
|
||||
* @param context
|
||||
* @param messageId
|
||||
*/
|
||||
@Override
|
||||
public void onNotificationRemoved(Context context, String messageId) {
|
||||
Log.i(TAG, "onNotificationRemoved : " + messageId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 无动作通知点击回调。当在后台或阿里云控制台指定的通知动作为无逻辑跳转时,通知点击回调为onNotificationClickedWithNoAction而不是onNotificationOpened
|
||||
*
|
||||
* @param context
|
||||
* @param title
|
||||
* @param summary
|
||||
* @param extraMap
|
||||
*/
|
||||
@Override
|
||||
protected void onNotificationClickedWithNoAction(Context context, String title, String summary, String extraMap) {
|
||||
Log.i(TAG, "onNotificationClickedWithNoAction : " + " : " + title + " : " + summary + " : " + extraMap);
|
||||
}
|
||||
}
|
||||
17
app/src/main/java/com/uiuios/aios/push/tpush/Constants.java
Normal file
17
app/src/main/java/com/uiuios/aios/push/tpush/Constants.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package com.uiuios.aios.push.tpush;
|
||||
|
||||
/**
|
||||
* Created by chacewang on 2019/7/5.
|
||||
*/
|
||||
|
||||
public class Constants {
|
||||
public static final int TEST_LOCAL_NOTIFICATION = 1;
|
||||
public static final int TEST_NOTIFICATION = 2;
|
||||
public static final int TEST_SET_TAG = 3;
|
||||
public static final int TEST_DEL_TAG = 4;
|
||||
public static final int TEST_SET_ACCOUNT = 5;
|
||||
public static final int TEST_DEL_ACCOUNT = 6;
|
||||
|
||||
public static final String LOCAL_NOTIFICATION_TITLE = "localtest";
|
||||
public static final String TEST_TAG_NAME = "DiagnosisTag";
|
||||
}
|
||||
@@ -0,0 +1,305 @@
|
||||
package com.uiuios.aios.push.tpush;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.tencent.android.tpush.NotificationAction;
|
||||
import com.tencent.android.tpush.XGPushBaseReceiver;
|
||||
import com.tencent.android.tpush.XGPushClickedResult;
|
||||
import com.tencent.android.tpush.XGPushRegisterResult;
|
||||
import com.tencent.android.tpush.XGPushShowedResult;
|
||||
import com.tencent.android.tpush.XGPushTextMessage;
|
||||
import com.uiuios.aios.push.PushManager;
|
||||
import com.uiuios.aios.push.tpush.common.NotificationService;
|
||||
import com.uiuios.aios.push.tpush.po.XGNotification;
|
||||
import com.uiuios.aios.utils.ToastUtil;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
|
||||
public class MessageReceiver extends XGPushBaseReceiver {
|
||||
private static final String TAG = MessageReceiver.class.getSimpleName();
|
||||
|
||||
public static final String UPDATE_LISTVIEW_ACTION = "com.qq.xgdemo.activity.UPDATE_LISTVIEW";
|
||||
public static final String TEST_ACTION = "com.qq.xgdemo.activity.TEST_ACTION";
|
||||
public static final String LogTag = "xg.test";
|
||||
|
||||
private Context mContext;
|
||||
private ContentResolver mResolver;
|
||||
private PackageManager mPackageManager;
|
||||
|
||||
/**
|
||||
* 消息透传处理
|
||||
*
|
||||
* @param context
|
||||
* @param message 解析自定义的 JSON
|
||||
*/
|
||||
@Override
|
||||
public void onTextMessage(Context context, XGPushTextMessage message) {
|
||||
this.mContext = context;
|
||||
this.mResolver = context.getContentResolver();
|
||||
this.mPackageManager = context.getPackageManager();
|
||||
String text = "收到消息:" + message.toString();
|
||||
// 获取自定义key-value
|
||||
String customContent = message.getCustomContent();
|
||||
if (customContent != null && customContent.length() != 0) {
|
||||
JsonObject obj = JsonParser.parseString(customContent).getAsJsonObject();
|
||||
// key1为前台配置的key
|
||||
if (!TextUtils.isEmpty(obj.get("key").getAsString())) {
|
||||
String value = obj.get("key").getAsString();
|
||||
Log.d(LogTag, "get custom value:" + value);
|
||||
}
|
||||
// ...
|
||||
}
|
||||
// APP自主处理消息的过程...
|
||||
Log.e(LogTag, text);
|
||||
show(context, text);
|
||||
processCustomMessage(context, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通知展示
|
||||
*
|
||||
* @param context
|
||||
* @param notifiShowedRlt 包含通知的内容
|
||||
*/
|
||||
@Override
|
||||
public void onNotificationShowedResult(Context context, XGPushShowedResult notifiShowedRlt) {
|
||||
if (context == null || notifiShowedRlt == null) {
|
||||
return;
|
||||
}
|
||||
XGNotification notific = new XGNotification();
|
||||
notific.setMsg_id(notifiShowedRlt.getMsgId());
|
||||
notific.setTitle(notifiShowedRlt.getTitle());
|
||||
notific.setContent(notifiShowedRlt.getContent());
|
||||
// notificationActionType==1为Activity,2为url,3为intent
|
||||
notific.setNotificationActionType(notifiShowedRlt
|
||||
.getNotificationActionType());
|
||||
// Activity,url,intent都可以通过getActivity()获得
|
||||
notific.setActivity(notifiShowedRlt.getActivity());
|
||||
notific.setUpdate_time(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
|
||||
.format(Calendar.getInstance().getTime()));
|
||||
NotificationService.getInstance(context).save(notific);
|
||||
|
||||
Intent testIntent = new Intent(TEST_ACTION);
|
||||
if (notifiShowedRlt.getTitle().equals(Constants.LOCAL_NOTIFICATION_TITLE)) {
|
||||
testIntent.putExtra("step", Constants.TEST_LOCAL_NOTIFICATION);
|
||||
} else {
|
||||
testIntent.putExtra("step", Constants.TEST_NOTIFICATION);
|
||||
}
|
||||
context.sendBroadcast(testIntent);
|
||||
|
||||
Intent viewIntent = new Intent(UPDATE_LISTVIEW_ACTION);
|
||||
context.sendBroadcast(viewIntent);
|
||||
show(context, "您有1条新消息, " + "通知被展示 , " + notifiShowedRlt.toString());
|
||||
Log.d(LogTag, "您有1条新消息, " + "通知被展示 , " + notifiShowedRlt.toString() + ", PushChannel:" + notifiShowedRlt.getPushChannel());
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册回调
|
||||
*
|
||||
* @param context
|
||||
* @param errorCode 0 为成功,其它为错误码
|
||||
*/
|
||||
@Override
|
||||
public void onRegisterResult(Context context, int errorCode, XGPushRegisterResult message) {
|
||||
if (context == null || message == null) {
|
||||
return;
|
||||
}
|
||||
String text = "";
|
||||
if (errorCode == XGPushBaseReceiver.SUCCESS) {
|
||||
// 在这里拿token
|
||||
String token = message.getToken();
|
||||
text = "注册成功1. token:" + token;
|
||||
} else {
|
||||
text = message + "注册失败,错误码:" + errorCode;
|
||||
}
|
||||
Log.d(LogTag, text);
|
||||
show(context, text);
|
||||
}
|
||||
|
||||
/**
|
||||
* 反注册回调
|
||||
*
|
||||
* @param context
|
||||
* @param errorCode 0 为成功,其它为错误码
|
||||
*/
|
||||
@Override
|
||||
public void onUnregisterResult(Context context, int errorCode) {
|
||||
if (context == null) {
|
||||
return;
|
||||
}
|
||||
String text = "";
|
||||
if (errorCode == XGPushBaseReceiver.SUCCESS) {
|
||||
text = "反注册成功";
|
||||
} else {
|
||||
text = "反注册失败" + errorCode;
|
||||
}
|
||||
Log.d(LogTag, text);
|
||||
show(context, text);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置标签回调
|
||||
*
|
||||
* @param context
|
||||
* @param errorCode 0 为成功,其它为错误码
|
||||
* @param tagName 设置的 TAG
|
||||
*/
|
||||
@Override
|
||||
public void onSetTagResult(Context context, int errorCode, String tagName) {
|
||||
if (context == null) {
|
||||
return;
|
||||
}
|
||||
String text = "";
|
||||
if (errorCode == XGPushBaseReceiver.SUCCESS) {
|
||||
text = "\"" + tagName + "\"设置成功";
|
||||
} else {
|
||||
text = "\"" + tagName + "\"设置失败,错误码:" + errorCode;
|
||||
}
|
||||
Log.d(LogTag, text);
|
||||
show(context, text);
|
||||
|
||||
Intent testIntent = new Intent(TEST_ACTION);
|
||||
testIntent.putExtra("step", Constants.TEST_SET_TAG);
|
||||
context.sendBroadcast(testIntent);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除标签的回调
|
||||
*
|
||||
* @param context
|
||||
* @param errorCode 0 为成功,其它为错误码
|
||||
* @param tagName 设置的 TAG
|
||||
*/
|
||||
@Override
|
||||
public void onDeleteTagResult(Context context, int errorCode, String tagName) {
|
||||
if (context == null) {
|
||||
return;
|
||||
}
|
||||
String text = "";
|
||||
if (errorCode == XGPushBaseReceiver.SUCCESS) {
|
||||
text = "\"" + tagName + "\"删除成功";
|
||||
} else {
|
||||
text = "\"" + tagName + "\"删除失败,错误码:" + errorCode;
|
||||
}
|
||||
Log.d(LogTag, text);
|
||||
show(context, text);
|
||||
|
||||
Intent testIntent = new Intent(TEST_ACTION);
|
||||
testIntent.putExtra("step", Constants.TEST_DEL_TAG);
|
||||
context.sendBroadcast(testIntent);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置账号回调
|
||||
*
|
||||
* @param context
|
||||
* @param errorCode 0 为成功,其它为错误码
|
||||
* @param account 设置的账号
|
||||
*/
|
||||
@Override
|
||||
public void onSetAccountResult(Context context, int errorCode, String account) {
|
||||
Intent testIntent = new Intent(TEST_ACTION);
|
||||
testIntent.putExtra("step", Constants.TEST_SET_ACCOUNT);
|
||||
context.sendBroadcast(testIntent);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除账号回调
|
||||
*
|
||||
* @param context
|
||||
* @param errorCode 0 为成功,其它为错误码
|
||||
* @param account 设置的账号
|
||||
*/
|
||||
@Override
|
||||
public void onDeleteAccountResult(Context context, int errorCode, String account) {
|
||||
Intent testIntent = new Intent(TEST_ACTION);
|
||||
testIntent.putExtra("step", Constants.TEST_DEL_ACCOUNT);
|
||||
context.sendBroadcast(testIntent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetAttributeResult(Context context, int i, String s) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeleteAttributeResult(Context context, int i, String s) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onQueryTagsResult(Context context, int errorCode, String data, String operateName) {
|
||||
Log.i(LogTag, "action - onQueryTagsResult, errorCode:" + errorCode + ", operateName:" + operateName + ", data: " + data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通知点击回调 actionType=1为该消息被清除,actionType=0为该消息被点击
|
||||
*
|
||||
* @param context
|
||||
* @param message 包含被点击通知的内容
|
||||
*/
|
||||
@Override
|
||||
public void onNotificationClickedResult(Context context, XGPushClickedResult message) {
|
||||
if (context == null || message == null) {
|
||||
return;
|
||||
}
|
||||
String text = "";
|
||||
if (message.getActionType() == NotificationAction.clicked.getType()) {
|
||||
// 通知在通知栏被点击啦。。。。。
|
||||
// APP自己处理点击的相关动作
|
||||
// 这个动作可以在activity的onResume也能监听,请看第3点相关内容
|
||||
text = "通知被打开 :" + message;
|
||||
} else if (message.getActionType() == NotificationAction.delete.getType()) {
|
||||
// 通知被清除啦。。。。
|
||||
// APP自己处理通知被清除后的相关动作
|
||||
text = "通知被清除 :" + message;
|
||||
}
|
||||
Toast.makeText(context, "广播接收到通知被点击:" + message.toString(),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
// 获取自定义key-value
|
||||
String customContent = message.getCustomContent();
|
||||
if (customContent != null && customContent.length() != 0) {
|
||||
JsonObject obj = JsonParser.parseString(customContent).getAsJsonObject();
|
||||
// key1为前台配置的key
|
||||
if (!TextUtils.isEmpty(obj.get("key").getAsString())) {
|
||||
String value = obj.get("key").getAsString();
|
||||
Log.d(LogTag, "get custom value:" + value);
|
||||
}
|
||||
// ...
|
||||
}
|
||||
// APP自主处理的过程。。。
|
||||
Log.d(LogTag, text);
|
||||
show(context, text);
|
||||
}
|
||||
|
||||
private void show(Context context, String text) {
|
||||
// Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
private void processCustomMessage(Context context, XGPushTextMessage message) {
|
||||
if (context == null || message == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String title = message.getTitle();
|
||||
String content = message.getContent();
|
||||
JsonObject extrasJson = JsonParser.parseString(content).getAsJsonObject();
|
||||
|
||||
String extras = "";
|
||||
if (extrasJson.get("extras") != null) {
|
||||
extras = extrasJson.get("extras").toString();
|
||||
}
|
||||
PushManager.getInstance().setPushContent(title, extras);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.uiuios.aios.push.tpush.common;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
|
||||
public class DBOpenHelper extends SQLiteOpenHelper {
|
||||
|
||||
public DBOpenHelper(Context context) {
|
||||
super(context, "XGExample.db", null, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
db.execSQL("CREATE TABLE notification (id integer primary key autoincrement,msg_id varchar(64),title varchar(128),activity varchar(256),notificationActionType varchar(512),content text,update_time varchar(16))");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
package com.uiuios.aios.push.tpush.common;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
|
||||
|
||||
import com.uiuios.aios.push.tpush.po.XGNotification;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class NotificationService {
|
||||
private DBOpenHelper dbOpenHelper;
|
||||
private static NotificationService instance = null;
|
||||
|
||||
public NotificationService(Context context) {
|
||||
this.dbOpenHelper = new DBOpenHelper(context);
|
||||
}
|
||||
|
||||
public synchronized static NotificationService getInstance(Context ctx) {
|
||||
if (null == instance) {
|
||||
instance = new NotificationService(ctx);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void save(XGNotification notification) {
|
||||
SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
|
||||
ContentValues values = new ContentValues();
|
||||
values.put("msg_id", notification.getMsg_id());
|
||||
values.put("title", notification.getTitle());
|
||||
values.put("content", notification.getContent());
|
||||
values.put("activity", notification.getActivity());
|
||||
values.put("notificationActionType", notification.getNotificationActionType());
|
||||
values.put("update_time", notification.getUpdate_time());
|
||||
db.insert("notification", null, values);
|
||||
}
|
||||
|
||||
public void delete(Integer id) {
|
||||
SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
|
||||
db.delete("notification", "id=?", new String[] { id.toString() });
|
||||
}
|
||||
|
||||
public void deleteAll() {
|
||||
SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
|
||||
db.delete("notification", "", null);
|
||||
}
|
||||
|
||||
public void update(XGNotification notification) {
|
||||
SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
|
||||
ContentValues values = new ContentValues();
|
||||
values.put("msg_id", notification.getMsg_id());
|
||||
values.put("title", notification.getTitle());
|
||||
values.put("content", notification.getContent());
|
||||
values.put("activity", notification.getActivity());
|
||||
values.put("notificationActionType", notification.getNotificationActionType());
|
||||
values.put("update_time", notification.getUpdate_time());
|
||||
db.update("notification", values, "id=?", new String[] { notification
|
||||
.getId().toString() });
|
||||
}
|
||||
|
||||
public XGNotification find(Integer id) {
|
||||
SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
|
||||
Cursor cursor = db
|
||||
.query("notification",
|
||||
new String[] { "id,msg_id,title,content,activity,notificationActionType,update_time" },
|
||||
"id=?", new String[] { id.toString() }, null, null,
|
||||
null, "1");
|
||||
try {
|
||||
if (cursor.moveToFirst()) {
|
||||
return new XGNotification(cursor.getInt(cursor
|
||||
.getColumnIndex("id")), cursor.getLong(cursor
|
||||
.getColumnIndex("msg_id")), cursor.getString(cursor
|
||||
.getColumnIndex("title")), cursor.getString(cursor
|
||||
.getColumnIndex("content")), cursor.getString(cursor
|
||||
.getColumnIndex("activity")), cursor.getInt(cursor
|
||||
.getColumnIndex("notificationActionType")), cursor.getString(cursor
|
||||
.getColumnIndex("update_time")));
|
||||
}
|
||||
return null;
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
public List<XGNotification> getScrollData(int currentPage, int lineSize,
|
||||
String msg_id) {
|
||||
String firstResult = String.valueOf((currentPage - 1) * lineSize);
|
||||
SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
if (msg_id == null || "".equals(msg_id)) {
|
||||
cursor = db
|
||||
.query("notification",
|
||||
new String[] { "id,msg_id,title,content,activity,notificationActionType,update_time" },
|
||||
null, null, null, null, "update_time DESC",
|
||||
firstResult + "," + lineSize);
|
||||
} else {
|
||||
cursor = db
|
||||
.query("notification",
|
||||
new String[] { "id,msg_id,title,content,activity,notificationActionType,update_time" },
|
||||
"msg_id like ?", new String[] { msg_id + "%" },
|
||||
null, null, "update_time DESC", firstResult
|
||||
+ "," + lineSize);
|
||||
}
|
||||
List<XGNotification> notifications = new ArrayList<XGNotification>();
|
||||
while (cursor.moveToNext()) {
|
||||
notifications.add(new XGNotification(cursor.getInt(cursor
|
||||
.getColumnIndex("id")), cursor.getLong(cursor
|
||||
.getColumnIndex("msg_id")), cursor.getString(cursor
|
||||
.getColumnIndex("title")), cursor.getString(cursor
|
||||
.getColumnIndex("content")), cursor.getString(cursor
|
||||
.getColumnIndex("activity")), cursor.getInt(cursor
|
||||
.getColumnIndex("notificationActionType")), cursor.getString(cursor
|
||||
.getColumnIndex("update_time"))));
|
||||
}
|
||||
return notifications;
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
|
||||
Cursor cursor = db.rawQuery("select count(*) from notification", null);
|
||||
try {
|
||||
cursor.moveToFirst();
|
||||
return cursor.getInt(0);
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.uiuios.aios.push.tpush.po;
|
||||
|
||||
public class XGNotification {
|
||||
private Integer id;
|
||||
private Long msg_id;
|
||||
private String title;
|
||||
private String content;
|
||||
private String activity;
|
||||
private int notificationActionType;
|
||||
private String update_time;
|
||||
|
||||
public XGNotification() {
|
||||
|
||||
}
|
||||
|
||||
public XGNotification(Integer id, Long msg_id, String title,
|
||||
String content, String activity, int notificationActionType, String update_time) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.msg_id = msg_id;
|
||||
this.title = title;
|
||||
this.content = content;
|
||||
this.activity = activity;
|
||||
this.notificationActionType = notificationActionType;
|
||||
this.update_time = update_time;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getMsg_id() {
|
||||
return msg_id;
|
||||
}
|
||||
|
||||
public void setMsg_id(Long msg_id) {
|
||||
this.msg_id = msg_id;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getUpdate_time() {
|
||||
return update_time;
|
||||
}
|
||||
|
||||
public void setUpdate_time(String update_time) {
|
||||
this.update_time = update_time;
|
||||
}
|
||||
|
||||
public String getActivity() {
|
||||
return activity;
|
||||
}
|
||||
|
||||
public void setActivity(String activity) {
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
public int getNotificationActionType() {
|
||||
return notificationActionType;
|
||||
}
|
||||
|
||||
public void setNotificationActionType(int notificationActionType) {
|
||||
this.notificationActionType = notificationActionType;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user