fix:
update:修改包名
This commit is contained in:
2025-11-28 20:50:52 +08:00
parent a34a680689
commit 7e16ba8813
298 changed files with 1063 additions and 1078 deletions

View File

@@ -0,0 +1,93 @@
package com.xwad.os.push;
import android.annotation.SuppressLint;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import com.xwad.os.disklrucache.CacheHelper;
import com.xwad.os.fragment.user.UserFragment;
import com.xwad.os.network.NetInterfaceManager;
import com.hjq.toast.Toaster;
public class PushManager {
private static final String TAG = "PushManager";
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 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";
/*网课模式*/
private static final String ONLINE_COURSE_MODE = "71";
/*作业提醒*/
private static final String HOMEWORK_REMINDERS = "115";
/*爱的鼓励*/
private static final String LOVE_ENCOURAGEMENT = "121";
public void setPushContent(String title, String extras) {
switch (title) {
case JIGUANG_ALARM_CLOCK:
Toaster.debugShow("收到推送消息: 设置闹钟");
sendAlarmClock(extras);
break;
case ONLINE_COURSE_MODE:
Toaster.debugShow("收到推送消息: 网课模式");
NetInterfaceManager.getInstance().getCloudLessonSettings();
break;
case HOMEWORK_REMINDERS:
sendHomework(extras);
break;
case LOVE_ENCOURAGEMENT:
Toaster.debugShow("收到推送消息: 爱的鼓励");
sendEncouragement(extras);
default:
}
}
private void sendAlarmClock(String extras) {
NetInterfaceManager.getInstance().getAlarmClock();
Intent intent = new Intent(SET_ALARMCLOCK);
mContext.sendBroadcast(intent);
}
private void sendHomework(String extras) {
Intent intent = new Intent(UserFragment.ACTION_REFRESH_HOMEWORK_REMINDERS);
mContext.sendBroadcast(intent);
}
private void sendEncouragement(String extras) {
Intent intent = new Intent(UserFragment.ACTION_REFRESH_LOVE_ENCOURAGEMENT);
mContext.sendBroadcast(intent);
}
}

View File

@@ -0,0 +1,99 @@
package com.xwad.os.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";
/**
* 推送通知的回调方法
*
* @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);
}
}

View File

@@ -0,0 +1,116 @@
package com.xwad.os.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.xwad.os.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";
/**
* 推送通知的回调方法
*
* @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);
}
}