| New file |
| | |
| | | package com.hdl.photovoltaic.push.aliyun; |
| | | |
| | | |
| | | import android.content.Context; |
| | | import android.util.Log; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.sdk.android.push.MessageReceiver; |
| | | import com.alibaba.sdk.android.push.notification.CPushMessage; |
| | | import com.hdl.photovoltaic.other.HdlPushLogic; |
| | | import com.hdl.photovoltaic.push.CustomNotification; |
| | | import com.hdl.photovoltaic.push.PushMessageInfoBean; |
| | | import com.hdl.photovoltaic.uni.HDLUniMPSDKManager; |
| | | |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 阿里云推送消息接收方法 |
| | | * 文档地址(https://help.aliyun.com/document_detail/434669.html?scm=20140722.S_help%40%40%E6%96%87%E6%A1%A3%40%40434669._.ID_help%40%40%E6%96%87%E6%A1%A3%40%40434669-RL_onNotificationOpened-LOC_doc%7EUND%7Eab-OR_ser-PAR1_212a5d4017647281629576475d8240-V_4-PAR3_r-RE_new8-P0_1-P1_0&spm=a2c4g.11186623.help-search.i10#section-kk1-wnc-oyd) |
| | | */ |
| | | public class MyAliYunMessageReceiver extends MessageReceiver { |
| | | private static final String TAG = "MyAliYunMessageReceiver"; |
| | | |
| | | /** |
| | | * 触发场景:当通知到达设备时触发。注意:这个方法在通知被展示到通知栏之前调用。 |
| | | * 参数说明: |
| | | * |
| | | * @param context:上下文 |
| | | * @param title:通知标题 |
| | | * @param content:通知内容 |
| | | * @param extraMap:额外的参数,用于自定义key-value |
| | | */ |
| | | |
| | | @Override |
| | | protected void onNotification(Context context, String title, String content, Map<String, String> extraMap) { |
| | | Log.d(TAG, "onNotification: " + JSON.toJSONString(extraMap)); |
| | | // CustomNotification.getInstance().messageDataProcessing(context, title, content, JSON.toJSONString(extraMap)); |
| | | } |
| | | |
| | | /** |
| | | * 触发场景:当应用内消息到达时触发。应用内消息不会展示在通知栏,而是直接传递给应用处理。通常用于应用内消息透传。 |
| | | * 参数说明: |
| | | * |
| | | * @param context:上下文 |
| | | * @param cPushMessage:消息对象,包含消息ID、标题、内容等。 |
| | | */ |
| | | @Override |
| | | protected void onMessage(Context context, CPushMessage cPushMessage) { |
| | | // String title = cPushMessage.getTitle(); |
| | | // String content = cPushMessage.getContent(); |
| | | // Log.d(TAG, "onMessage: " + JSON.toJSONString(cPushMessage)); |
| | | // if (isForeground) { |
| | | // //App处于前台,弹窗形式显示 |
| | | // } else { |
| | | // //App处于后台,通知形式显示 |
| | | // } |
| | | } |
| | | |
| | | /** |
| | | * 触发场景:当用户点击通知栏中的通知时触发。 |
| | | * 参数说明: |
| | | * |
| | | * @param context:上下文 |
| | | * @param title:通知标题 |
| | | * @param content:通知内容 |
| | | * @param extra:额外的参数字符串(JSON格式) |
| | | */ |
| | | @Override |
| | | protected void onNotificationOpened(Context context, String title, String content, String extra) { |
| | | Log.d(TAG, "onNotificationOpened: " + "title=" + title + " content=" + content + " extra=" + extra); |
| | | } |
| | | |
| | | /** |
| | | * 触发场景:当用户点击通知栏中的通知,但是无法启动应用时触发(例如应用被强制停止)。 |
| | | * 参数说明: |
| | | * |
| | | * @param context:上下文 |
| | | * @param title:通知标题 |
| | | * @param content:通知内容 |
| | | * @param extra:额外的参数字符串(JSON格式) |
| | | */ |
| | | @Override |
| | | protected void onNotificationClickedWithNoAction(Context context, String title, String content, String extra) { |
| | | Log.d(TAG, "onNotificationClickedWithNoAction: " + "title=" + title + " content=" + content + " extra=" + extra); |
| | | } |
| | | |
| | | /** |
| | | * 触发场景:当通知被清除时触发。例如,用户清除了通知栏中的通知。 |
| | | * 参数说明: |
| | | * |
| | | * @param context 上下文 |
| | | * @param messageId 被清除的消息ID |
| | | */ |
| | | @Override |
| | | protected void onNotificationRemoved(Context context, String messageId) { |
| | | Log.d(TAG, "onNotificationClickedWithNoAction: " + "messageId=" + messageId); |
| | | } |
| | | |
| | | /** |
| | | * 触发场景:当通知在应用内展示时触发。这个方法在showNotificationNow方法返回false时会被调用,表示拦截了通知的默认展示,转而使用应用内展示。 |
| | | * 参数说明: |
| | | * |
| | | * @param context:上下文 |
| | | * @param title:通知标题 |
| | | * @param content:通知内容 |
| | | * @param extraMap:额外的参数 |
| | | * @param openType:打开类型,例如打开应用、打开Activity、打开URL等(1:打开APP;2:打开activity;3:打开URL;4:无跳转逻辑。) |
| | | * @param openActivity:需要打开的Activity(所要打开的activity的名称,仅当服务端参数openType=2时有效,其余情况为null。) |
| | | * @param openUrl:需要打开的URL(所要打开的URL,仅当服务端参数openType=3时有效,其余情况为null。) |
| | | */ |
| | | @Override |
| | | protected void onNotificationReceivedInApp(Context context, String title, String content, Map<String, String> extraMap, int openType, String openActivity, String openUrl) { |
| | | //这里可以处理下发的推送通知 |
| | | Log.d(TAG, "onNotificationReceivedInApp:title=" + title |
| | | + " content=" + content + " extraMap=" + JSON.toJSONString(extraMap) + " openType=" |
| | | + openType + " openActivity=" + openActivity + " openUrl=" + openUrl); |
| | | //如果在前台时,发送通知让消息列表更新,在后台是,这里不会执行,会执行VendorChannelActivity.onSysNoticeOpened()的方法 |
| | | CustomNotification.getInstance().messageDataProcessing(context, title, content, JSON.toJSONString(extraMap),CustomNotification.FromPush.AliYun); |
| | | } |
| | | |
| | | /** |
| | | * 触发场景:在通知即将展示时触发。这个方法允许你决定是否拦截通知的默认展示行为。 |
| | | * 参数说明: |
| | | * |
| | | * @param context 上下文 |
| | | * @param extraMap 额外的参数 |
| | | * @return false表示拦截,true表示不拦截,请根据进行拦截,拦截后会执行到 onNotificationReceivedInApp |
| | | */ |
| | | @Override |
| | | public boolean showNotificationNow(Context context, Map<String, String> extraMap) { |
| | | //false表示拦截,true表示不拦截,请根据进行拦截,拦截后会执行到 onNotificationReceivedInApp |
| | | Log.d(TAG, "showNotificationNow:" + "extraMap=" + JSON.toJSONString(extraMap)); |
| | | return !CustomNotification.getInstance().isAppInForeground(context); |
| | | // return false; |
| | | } |
| | | } |