Commit a4de45ff by 刘鹏

Merge branch 'feat/qj_new_dev' into 'new_dev_4.3.91'

im pushpayload

See merge request app_android_lib/YDL-Component!2
parents 438c6e44 14d13898
......@@ -2,9 +2,15 @@ package com.yidianling.im.config;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import com.alibaba.fastjson.JSON;
import com.netease.nimlib.sdk.NIMClient;
import com.netease.nimlib.sdk.auth.LoginInfo;
import com.netease.nimlib.sdk.mixpush.MixPushMessageHandler;
import com.netease.nimlib.sdk.mixpush.NIMPushClient;
import com.netease.nimlib.sdk.uinfo.model.UserInfo;
import com.netease.nimlib.sdk.util.NIMUtil;
import com.ydl.ydlcommon.utils.SharedPreferencesEditor;
......@@ -28,6 +34,8 @@ import com.yidianling.uikit.business.uinfo.UserInfoHelper;
import com.yidianling.uikit.custom.config.YDLToolBarOptions;
import com.yidianling.user.api.bean.UserResponseBean;
import java.util.Map;
import de.greenrobot.event.EventBus;
......@@ -67,6 +75,32 @@ public class NimApplication {
ImObserversHelper.Companion.getInstance().registerObserver(true);
// 初始化听筒模式
initEarMode();
NIMPushClient.registerMixPushMessageHandler(new MixPushMessageHandler() {
@Override
public boolean onNotificationClicked(Context context, Map<String, String> map) {
Log.d("notification", JSON.toJSONString(map));
String routeAndroid = map.get("route_android");
if (routeAndroid != null) {
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setPackage(context.getPackageName());
intent.setData(Uri.parse(routeAndroid));
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
return true;
} catch (Throwable e) {
Log.e("app", "", e);
}
}
return false;
}
@Override
public boolean cleanMixPushNotifications(int i) {
return false;
}
});
}
}
......
......@@ -5,6 +5,7 @@ import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Handler;
import android.os.SystemClock;
import android.text.Editable;
......@@ -30,9 +31,9 @@ import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.blankj.utilcode.util.SPUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.netease.nimlib.sdk.NIMClient;
import com.netease.nimlib.sdk.media.record.AudioRecorder;
import com.netease.nimlib.sdk.media.record.IAudioRecordCallback;
......@@ -72,7 +73,9 @@ import com.yidianling.user.api.service.IUserService;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import de.greenrobot.event.EventBus;
import io.reactivex.functions.Consumer;
......@@ -645,7 +648,70 @@ public class InputPanel implements IEmoticonSelectedListener, IAudioRecordCallba
}
protected IMMessage createTextMessage(String text) {
return MessageBuilder.createTextMessage(container.account, container.sessionType, text);
IMMessage msg = MessageBuilder.createTextMessage(container.account, container.sessionType, text);
Map<String, Object> payload = new HashMap<>();
fillHwPayload(payload, NimUIKit.getAccount(), container.sessionType.getValue());
fillOppoPayload(payload, NimUIKit.getAccount(), container.sessionType.getValue());
fillVivoPayload(payload, NimUIKit.getAccount(), container.sessionType.getValue());
payload.put("sessionId", NimUIKit.getAccount());
payload.put("sessionType", container.sessionType.getValue());
msg.setPushPayload(payload);
return msg;
}
private void fillHwPayload(Map<String, Object> pushPayload, String sessionId, int sessionType) {
//华为
Intent hwIntent = new Intent(Intent.ACTION_VIEW);
String intentStr = String.format(
"im://ydl.com/session?sessionId=%s&sessionType=%s",
sessionId, // 发送者的account 或 群聊id
sessionType // 类型(单聊或群聊)
);
hwIntent.setData(Uri.parse(intentStr));
hwIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
String intentUri = hwIntent.toUri(Intent.URI_INTENT_SCHEME);
//点击事件的内容
JSONObject clickAction = new JSONObject();
//通知的内容
JSONObject notification = new JSONObject();
try {
clickAction.fluentPut("type", 1)
.put("intent", intentUri);
notification.put("click_action", clickAction);
pushPayload.put("hwField", notification);
} catch (JSONException e) {
e.printStackTrace();
}
}
private void fillVivoPayload(Map<String, Object> pushPayload, String sessionId, int sessionType) {
Map<String, Object> vivoField = new HashMap<>();
vivoField.put("classification", 1);
vivoField.put("skipType", 3);
Intent intent = new Intent(Intent.ACTION_VIEW);
String intentStr = String.format(
"im://ydl.com/session?sessionId=%s&sessionType=%s",
sessionId, // 发送者的account 或 群聊id
sessionType // 类型(单聊或群聊)
);
intent.setData(Uri.parse(intentStr));
String intentUri = intent.toUri(Intent.URI_INTENT_SCHEME);
vivoField.put("skipContent", intentUri);
pushPayload.put("vivoField", vivoField);
}
private void fillOppoPayload(Map<String, Object> pushPayload, String sessionId, int sessionType) {
Map<String, Object> oppoField = new HashMap<>();
String intentStr = String.format(
"im://ydl.com/session?sessionId=%s&sessionType=%s",
sessionId, // 发送者的account 或 群聊id
sessionType // 类型(单聊或群聊)
);
oppoField.put("click_action_type", 5);
oppoField.put("click_action_url", intentStr);
oppoField.put("channel_id", "nim_message_channel_001");
pushPayload.put("oppoField", oppoField);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment