Quellcode durchsuchen

增加学生端和老师端推送跳转问题

Pq vor 3 Jahren
Ursprung
Commit
aa7c34fa14

+ 1 - 0
BaseLibrary/src/main/java/com/cooleshow/base/utils/JumpUtils.java

@@ -101,6 +101,7 @@ public class JumpUtils {
 
     private static String getParams(String paramsJson, String key) {
         try {
+            paramsJson.replace("\\", "");
             JSONObject jsonObject = new JSONObject(paramsJson);
             return jsonObject.optString(key);
         } catch (Exception e) {

+ 27 - 1
student/src/main/AndroidManifest.xml

@@ -63,7 +63,33 @@
             android:exported="false"
             android:launchMode="singleTask"
             android:windowSoftInputMode="adjustPan"
-            android:screenOrientation="portrait" />
+            android:screenOrientation="portrait" >
+            <intent-filter>
+                <!-- 这个action是给极光推送跳转的 oppo推送要求push的intent-filter应与其他功能的intent-filter区分开,勿添加其他action与data标签-->
+                <action android:name="cn.jiguang.push.customAction" />
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
+
+            <intent-filter>
+                <!-- 这个action是给融云推送跳转的,比如华为的离线消息点击-->
+                <action android:name="android.intent.action.VIEW" />
+                <category android:name="android.intent.category.DEFAULT" />
+                <data
+                    android:host="${applicationId}"
+                    android:pathPrefix="/conversationlist"
+                    android:scheme="rong" />
+            </intent-filter>
+
+            <intent-filter>
+                <!-- 这个action是给融云推送跳转的,比如小米手机等消息点击-->
+                <action android:name="android.intent.action.VIEW" />
+                <category android:name="android.intent.category.DEFAULT" />
+                <data
+                    android:host="${applicationId}"
+                    android:pathPrefix="/conversation/"
+                    android:scheme="rong" />
+            </intent-filter>
+        </activity>
 
         <activity
             android:name=".ui.web.WebActivity"

+ 83 - 0
student/src/main/java/com/cooleshow/student/helper/PushIntentParseHelper.java

@@ -0,0 +1,83 @@
+package com.cooleshow.student.helper;
+
+import android.content.Intent;
+import android.net.Uri;
+import android.text.TextUtils;
+import android.util.Log;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+/**
+ * Author by pq, Date on 2022/5/27.
+ */
+public class PushIntentParseHelper {
+
+    public static final String RONG_PUSH_SCHEME = "rong";//融云推送scheme
+    public static final String RONG_PUSH_ACTION_TAG = "rongIM";//融云推送action
+
+
+    /**
+     * 处理点击事件,当前启动配置的Activity都是使用
+     * Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK
+     * 方式启动,只需要在onCreat中调用此方法进行处理
+     */
+
+    /**
+     * 通知附加字段
+     **/
+    private static final String KEY_EXTRAS = "n_extras";
+
+    private static String parsePushIntent(Intent intent) {
+        String data = null;
+
+        //获取华为平台附带的jpush信息
+        if (intent.getData() != null) {
+            data = intent.getData().toString();
+        }
+        //获取fcm/oppo/小米/vivo/魅族 平台附带的jpush信息
+        if (TextUtils.isEmpty(data) && intent.getExtras() != null) {
+            data = intent.getExtras().getString("JMessageExtra");
+        }
+        Log.i("pq", "msg content is " + String.valueOf(data));
+        return data;
+    }
+
+    private static String getMemoFromPushIntent(String intent) {
+        JSONObject jsonObject = null;
+        try {
+            jsonObject = new JSONObject(intent);
+            JSONObject n_extras = (JSONObject) jsonObject.opt(KEY_EXTRAS);
+            if (n_extras != null) {
+                return n_extras.optString("memo");
+            }
+        } catch (JSONException e) {
+            e.printStackTrace();
+        }
+        return "";
+    }
+
+
+    public static String getIntentMemoFrom(Intent intent) {
+        String memo = "";
+        Uri data = intent.getData();
+        if (data != null && data.isHierarchical()) {
+            //判断是否是融云推送
+            if (TextUtils.equals(RONG_PUSH_SCHEME, data.getScheme())) {
+                memo = RONG_PUSH_ACTION_TAG;
+            }
+        }
+        if (TextUtils.isEmpty(memo)) {
+            //判断是否是极光推送
+            String result = parsePushIntent(intent);
+            if (!TextUtils.isEmpty(result)) {
+                memo = getMemoFromPushIntent(result);
+            }
+        }
+
+        if (TextUtils.isEmpty(memo)) {
+            memo = intent.getStringExtra("memo");
+        }
+        return memo;
+    }
+}

+ 22 - 0
student/src/main/java/com/cooleshow/student/ui/main/MainActivity.java

@@ -17,11 +17,14 @@ import androidx.fragment.app.Fragment;
 
 import com.alibaba.android.arouter.facade.annotation.Route;
 import com.common.im.ui.MessageFragment;
+import com.cooleshow.base.bean.RouteBean;
 import com.cooleshow.base.common.BaseApplication;
 import com.cooleshow.base.constanst.LoginStatusConstants;
 import com.cooleshow.base.event.LoginStatusEvent;
 import com.cooleshow.base.router.RouterPath;
 import com.cooleshow.base.ui.activity.BaseMVPActivity;
+import com.cooleshow.base.utils.GsonUtils;
+import com.cooleshow.base.utils.JumpUtils;
 import com.cooleshow.base.utils.LogUtils;
 import com.cooleshow.base.utils.ToastUtil;
 import com.cooleshow.base.utils.helper.QMUIStatusBarHelper;
@@ -29,6 +32,7 @@ import com.cooleshow.student.R;
 import com.cooleshow.student.adapter.HomePageAdapter;
 import com.cooleshow.student.contract.MainContract;
 import com.cooleshow.student.databinding.ActivityMainBinding;
+import com.cooleshow.student.helper.PushIntentParseHelper;
 import com.cooleshow.student.presenter.main.MainPresenter;
 import com.cooleshow.usercenter.bean.UserInfo;
 import com.cooleshow.usercenter.helper.UserHelper;
@@ -37,6 +41,7 @@ import com.daya.live_teaching.im.IMManager;
 import com.google.android.material.bottomnavigation.BottomNavigationItemView;
 import com.google.android.material.bottomnavigation.BottomNavigationMenuView;
 import com.google.android.material.bottomnavigation.BottomNavigationView;
+import com.google.gson.Gson;
 import com.tbruyelle.rxpermissions3.RxPermissions;
 
 import org.greenrobot.eventbus.EventBus;
@@ -103,6 +108,23 @@ public class MainActivity extends BaseMVPActivity<ActivityMainBinding, MainPrese
                 return;
             }
             setPositionItem(selectPos);
+            return;
+        }
+        String intentResult = PushIntentParseHelper.getIntentMemoFrom(intent);
+        LogUtils.i("pq","intentResult:"+intentResult);
+        if (!TextUtils.isEmpty(intentResult)) {
+            if (TextUtils.equals(intentResult, PushIntentParseHelper.RONG_PUSH_ACTION_TAG)) {
+                //融云推送相关
+                //选中聊天
+                setPositionItem(2);
+                return;
+            }
+            try {
+                RouteBean routeBean = GsonUtils.fromJson(intentResult, RouteBean.class);
+                JumpUtils.jump(routeBean);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
         }
     }
 

+ 27 - 1
teacher/src/main/AndroidManifest.xml

@@ -73,7 +73,33 @@
             android:exported="false"
             android:launchMode="singleTask"
             android:screenOrientation="portrait"
-            android:windowSoftInputMode="adjustPan" />
+            android:windowSoftInputMode="adjustPan" >
+            <intent-filter>
+                <!-- 这个action是给极光推送跳转的 oppo推送要求push的intent-filter应与其他功能的intent-filter区分开,勿添加其他action与data标签-->
+                <action android:name="cn.jiguang.push.customAction" />
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
+
+            <intent-filter>
+                <!-- 这个action是给融云推送跳转的,比如华为的离线消息点击-->
+                <action android:name="android.intent.action.VIEW" />
+                <category android:name="android.intent.category.DEFAULT" />
+                <data
+                    android:host="${applicationId}"
+                    android:pathPrefix="/conversationlist"
+                    android:scheme="rong" />
+            </intent-filter>
+
+            <intent-filter>
+                <!-- 这个action是给融云推送跳转的,比如小米手机等消息点击-->
+                <action android:name="android.intent.action.VIEW" />
+                <category android:name="android.intent.category.DEFAULT" />
+                <data
+                    android:host="${applicationId}"
+                    android:pathPrefix="/conversation/"
+                    android:scheme="rong" />
+            </intent-filter>
+        </activity>
         <activity
             android:name=".ui.splash.GuideActivity"
             android:configChanges="orientation|screenSize|keyboardHidden"

+ 83 - 0
teacher/src/main/java/com/cooleshow/teacher/helper/PushIntentParseHelper.java

@@ -0,0 +1,83 @@
+package com.cooleshow.teacher.helper;
+
+import android.content.Intent;
+import android.net.Uri;
+import android.text.TextUtils;
+import android.util.Log;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+/**
+ * Author by pq, Date on 2022/5/27.
+ */
+public class PushIntentParseHelper {
+
+    public static final String RONG_PUSH_SCHEME = "rong";//融云推送scheme
+    public static final String RONG_PUSH_ACTION_TAG = "rongIM";//融云推送action
+
+
+    /**
+     * 处理点击事件,当前启动配置的Activity都是使用
+     * Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK
+     * 方式启动,只需要在onCreat中调用此方法进行处理
+     */
+
+    /**
+     * 通知附加字段
+     **/
+    private static final String KEY_EXTRAS = "n_extras";
+
+    private static String parsePushIntent(Intent intent) {
+        String data = null;
+
+        //获取华为平台附带的jpush信息
+        if (intent.getData() != null) {
+            data = intent.getData().toString();
+        }
+        //获取fcm/oppo/小米/vivo/魅族 平台附带的jpush信息
+        if (TextUtils.isEmpty(data) && intent.getExtras() != null) {
+            data = intent.getExtras().getString("JMessageExtra");
+        }
+        Log.i("pq", "msg content is " + String.valueOf(data));
+        return data;
+    }
+
+    private static String getMemoFromPushIntent(String intent) {
+        JSONObject jsonObject = null;
+        try {
+            jsonObject = new JSONObject(intent);
+            JSONObject n_extras = (JSONObject) jsonObject.opt(KEY_EXTRAS);
+            if (n_extras != null) {
+                return n_extras.optString("memo");
+            }
+        } catch (JSONException e) {
+            e.printStackTrace();
+        }
+        return "";
+    }
+
+
+    public static String getIntentMemoFrom(Intent intent) {
+        String memo = "";
+        Uri data = intent.getData();
+        if (data != null && data.isHierarchical()) {
+            //判断是否是融云推送
+            if (TextUtils.equals(RONG_PUSH_SCHEME, data.getScheme())) {
+                memo = RONG_PUSH_ACTION_TAG;
+            }
+        }
+        if (TextUtils.isEmpty(memo)) {
+            //判断是否是极光推送
+            String result = parsePushIntent(intent);
+            if (!TextUtils.isEmpty(result)) {
+                memo = getMemoFromPushIntent(result);
+            }
+        }
+
+        if (TextUtils.isEmpty(memo)) {
+            memo = intent.getStringExtra("memo");
+        }
+        return memo;
+    }
+}

+ 20 - 0
teacher/src/main/java/com/cooleshow/teacher/ui/main/MainActivity.java

@@ -13,11 +13,14 @@ import android.widget.TextView;
 
 import com.alibaba.android.arouter.facade.annotation.Route;
 import com.common.im.ui.MessageFragment;
+import com.cooleshow.base.bean.RouteBean;
 import com.cooleshow.base.common.BaseApplication;
 import com.cooleshow.base.constanst.LoginStatusConstants;
 import com.cooleshow.base.event.LoginStatusEvent;
 import com.cooleshow.base.router.RouterPath;
 import com.cooleshow.base.ui.activity.BaseMVPActivity;
+import com.cooleshow.base.utils.GsonUtils;
+import com.cooleshow.base.utils.JumpUtils;
 import com.cooleshow.base.utils.LogUtils;
 import com.cooleshow.base.utils.ToastUtil;
 import com.cooleshow.base.utils.helper.QMUIStatusBarHelper;
@@ -26,6 +29,7 @@ import com.cooleshow.teacher.adapter.HomePageAdapter;
 import com.cooleshow.teacher.bean.TeacherUserInfo;
 import com.cooleshow.teacher.contract.MainContract;
 import com.cooleshow.teacher.databinding.ActivityMainBinding;
+import com.cooleshow.teacher.helper.PushIntentParseHelper;
 import com.cooleshow.teacher.presenter.main.MainPresenter;
 import com.cooleshow.usercenter.bean.UserInfo;
 import com.cooleshow.usercenter.helper.UserHelper;
@@ -110,6 +114,22 @@ public class MainActivity extends BaseMVPActivity<ActivityMainBinding, MainPrese
             }
             setPositionItem(selectPos);
         }
+        String intentResult = PushIntentParseHelper.getIntentMemoFrom(intent);
+        LogUtils.i("pq","intentResult:"+intentResult);
+        if (!TextUtils.isEmpty(intentResult)) {
+            if (TextUtils.equals(intentResult, PushIntentParseHelper.RONG_PUSH_ACTION_TAG)) {
+                //融云推送相关
+                //选中聊天
+                setPositionItem(2);
+                return;
+            }
+            try {
+                RouteBean routeBean = GsonUtils.fromJson(intentResult, RouteBean.class);
+                JumpUtils.jump(routeBean);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
     }
 
     @Override