Browse Source

增加学生端推送

Pq 2 years ago
parent
commit
829a62aa89

+ 29 - 2
student/build.gradle

@@ -26,7 +26,17 @@ android {
         }
         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
         manifestPlaceholders = [
-                qqappid: "1110018403"
+                qqappid: "1110018403",
+                JPUSH_PKGNAME: applicationId,
+                JPUSH_APPKEY : "911d07f359c18a078f29792f", //JPush 上注册的包名对应的 Appkey.
+                JPUSH_CHANNEL: "developer-default", //暂时填写默认值即可.
+                XIAOMI_APPID : "MI-2882303761520170306",
+                XIAOMI_APPKEY : "MI-5802017024306",
+                OPPO_APPKEY : "OP-5b2b716e774c45f2bd9a90b242b295e9",
+                OPPO_APPID : "OP-30841111",
+                OPPO_APPSECRET : "OP-3f1d849d8bce4273be48ca08a2ce320b",
+                VIVO_APPKEY : "ebf526d1d61ab3bba65ce30d333189f3",
+                VIVO_APPID : "105573871",
         ]
     }
 
@@ -98,5 +108,22 @@ dependencies {
     kapt "com.alibaba:arouter-compiler:$rootProject.ext.android.arouter_api_version"
 
 //    api(name: 'openDefault-10.10.0', ext: 'aar')
-
+//    极光推送start
+    implementation 'cn.jiguang.sdk:jpush:4.7.2'  // 此处以JPush 4.7.0 版本为例。
+    implementation 'cn.jiguang.sdk:jcore:3.2.4'  // 此处以JCore 3.2.4 版本为例。
+    //若不集成厂商通道,可直接跳过以下依赖
+    // 接入华为厂商
+    implementation 'com.huawei.hms:push:6.3.0.304'
+    // 极光厂商插件版本与接入 JPush 版本保持一致,下同
+    implementation 'cn.jiguang.sdk.plugin:huawei:4.7.2'
+    // 接入 VIVO 厂商
+    implementation 'cn.jiguang.sdk.plugin:vivo:4.7.2'
+    // 接入小米厂商
+    implementation 'cn.jiguang.sdk.plugin:xiaomi:4.7.2'
+    // 接入 OPPO 厂商
+    implementation 'cn.jiguang.sdk.plugin:oppo:4.7.2'
+    // JPush Android SDK v4.6.0 开始,需要单独引入 oppo 厂商 aar ,请下载官网 SDK 包并把 jpush-android-xxx-release/third-push/oppo/libs 下的 com.heytap.msp-push-x.x.x.aar 文件单独拷贝一份到应用 module/libs 下
+    implementation(name: 'com.heytap.msp-push-3.0.0', ext: 'aar')
+    implementation 'commons-codec:commons-codec:1.6'
+//    极光推送end
 }

BIN
student/libs/com.heytap.msp-push-3.0.0.aar


+ 28 - 2
student/proguard-rules.pro

@@ -33,7 +33,7 @@
 }
 
 # for DexGuard only
--keepresourcexmlelements manifest/application/meta-data@value=GlideModule
+-keep resourcexmlelements manifest/application/meta-data@value=GlideModule
 
 #融云SDK
 -keepattributes Exceptions,InnerClasses
@@ -51,4 +51,30 @@
 -dontnote com.google.android.gms.gcm.**
 -dontnote io.rong.**
 
--ignorewarnings
+-ignorewarnings
+
+-dontwarn com.xiaomi.push.**
+-keep class com.xiaomi.push.** { *; }
+
+-ignorewarnings
+-keepattributes *Annotation*
+-keepattributes Exceptions
+-keepattributes InnerClasses
+-keepattributes Signature
+-keepattributes SourceFile,LineNumberTable
+-keep class com.hianalytics.android.**{*;}
+-keep class com.huawei.updatesdk.**{*;}
+-keep class com.huawei.hms.**{*;}
+
+-dontwarn com.vivo.push.**
+-keep class com.vivo.push.**{*; }
+-keep class com.vivo.vms.**{*; }
+
+-dontwarn com.coloros.mcsdk.**
+-keep class com.coloros.mcsdk.** { *; }
+
+-dontwarn com.heytap.**
+-keep class com.heytap.** { *; }
+
+-dontwarn com.mcs.**
+-keep class com.mcs.** { *; }

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

@@ -4,7 +4,13 @@
     package="com.cooleshow.student">
 
     <uses-permission android:name="android.permission.REORDER_TASKS" />
-
+    <permission
+        android:name="${applicationId}.permission.JPUSH_MESSAGE"
+        android:protectionLevel="signature" />
+    <uses-permission android:name="${applicationId}.permission.JPUSH_MESSAGE" />
+    <permission
+        android:name="${applicationId}.permission.MIPUSH_RECEIVE"
+        android:protectionLevel="signature" />
 
     <queries>
         <package android:name="com.tencent.mm" />           <!-- // 指定微信包名-->
@@ -238,6 +244,44 @@
             android:value="1110018403" />
         <!--        分享结束-->
 
+        <service
+            android:name=".push.PushService"
+            android:enabled="true"
+            android:exported="false"
+            android:process=":pushcore">
+            <intent-filter>
+                <action android:name="cn.jiguang.user.service.action" />
+            </intent-filter>
+        </service> <!-- User defined.  For test only  用户自定义的广播接收器 -->
+        <receiver
+            android:name=".push.MyJPushMessageReceiver"
+            android:enabled="true"
+            android:exported="false">
+            <intent-filter>
+                <action android:name="cn.jpush.android.intent.RECEIVE_MESSAGE" />
+
+                <category android:name="${applicationId}" />
+            </intent-filter>
+        </receiver> <!-- JPush结束 -->
+        <service
+            android:name=".push.MyHWPushService"
+            android:exported="false">
+            <intent-filter>
+                <action android:name="com.huawei.push.action.MESSAGING_EVENT" />
+            </intent-filter>
+        </service>
+        <!-- 融云开始 -->
+        <receiver
+            android:name=".push.SealNotificationReceiver"
+            android:exported="true">
+            <intent-filter>
+                <action android:name="io.rong.push.intent.MESSAGE_ARRIVED" />
+                <action android:name="io.rong.push.intent.MESSAGE_CLICKED" />
+                <action android:name="io.rong.push.intent.THIRD_PARTY_PUSH_STATE" />
+            </intent-filter>
+        </receiver>
+
+
     </application>
 
 </manifest>

+ 4 - 1
student/src/main/java/com/cooleshow/student/App.java

@@ -42,6 +42,7 @@ import com.umeng.socialize.PlatformConfig;
 import com.vanniktech.emoji.EmojiManager;
 import com.vanniktech.emoji.ios.IosEmojiProvider;
 
+import cn.jpush.android.api.JPushInterface;
 import io.reactivex.rxjava3.annotations.NonNull;
 import io.reactivex.rxjava3.core.Observable;
 import io.reactivex.rxjava3.core.ObservableEmitter;
@@ -76,7 +77,9 @@ public class App extends BaseApplication {
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
             webviewSetPath(this);
         }
-        registrationId ="";
+        //极光推送
+        JPushInterface.setDebugMode(true);
+        registrationId = JPushInterface.getRegistrationID(this);
         CrashReport.initCrashReport(getApplicationContext(), "b51fd73164", false);
         initRong();
         initUmeng();

+ 13 - 0
student/src/main/java/com/cooleshow/student/push/HuaWeiHMSReceiver.java

@@ -0,0 +1,13 @@
+package com.cooleshow.student.push;
+
+/**
+ * Description:
+ * Copyright  : Copyright (c) 2019
+ * Company    : 大雅乐盟
+ * Author     : r
+ * Date       : 2019/10/29 16:51
+ * extends HMSReceiver
+ */
+public class HuaWeiHMSReceiver  {
+
+}

+ 36 - 0
student/src/main/java/com/cooleshow/student/push/MyHWPushService.java

@@ -0,0 +1,36 @@
+package com.cooleshow.student.push;
+
+import com.huawei.hms.push.HmsMessageService;
+import com.huawei.hms.push.RemoteMessage;
+
+import cn.jpush.android.service.PluginHuaweiPlatformsService;
+
+public class MyHWPushService extends HmsMessageService {
+
+      final PluginHuaweiPlatformsService jpushService = new PluginHuaweiPlatformsService();
+
+      @Override
+      public void onNewToken(String s) {
+          jpushService.onNewToken(s);
+      }
+
+      @Override
+      public void onMessageReceived(RemoteMessage remoteMessage) {
+          jpushService.onMessageReceived(remoteMessage);
+      }
+
+      @Override
+      public void onMessageSent(String s) {
+          jpushService.onMessageSent(s);
+      }
+
+      @Override
+      public void onSendError(String s, Exception e) {
+          jpushService.onSendError(s,e);
+      }
+
+      @Override
+      public void onDeletedMessages() {
+          jpushService.onDeletedMessages();
+      }
+  }

+ 76 - 0
student/src/main/java/com/cooleshow/student/push/MyJPushMessageReceiver.java

@@ -0,0 +1,76 @@
+package com.cooleshow.student.push;
+
+import android.content.Context;
+
+import com.cooleshow.base.utils.LogUtils;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import cn.jpush.android.api.JPushMessage;
+import cn.jpush.android.api.NotificationMessage;
+import cn.jpush.android.service.JPushMessageReceiver;
+
+/**
+ * 自定义JPush message 接收器,包括操作tag/alias的结果返回(仅仅包含tag/alias新接口部分)
+ */
+public class MyJPushMessageReceiver extends JPushMessageReceiver {
+
+    private String memo;
+
+    /**
+     * 用户点击打开了通知
+     * @param context
+     * @param notificationMessage
+     */
+    @Override
+    public void onNotifyMessageOpened(Context context, NotificationMessage notificationMessage) {
+        startActivity(context, notificationMessage);
+    }
+
+    @Override
+    public void onTagOperatorResult(Context context, JPushMessage jPushMessage) {
+        super.onTagOperatorResult(context, jPushMessage);
+    }
+
+    @Override
+    public void onCheckTagOperatorResult(Context context, JPushMessage jPushMessage) {
+        super.onCheckTagOperatorResult(context, jPushMessage);
+    }
+
+    @Override
+    public void onAliasOperatorResult(Context context, JPushMessage jPushMessage) {
+        super.onAliasOperatorResult(context, jPushMessage);
+    }
+
+    @Override
+    public void onMobileNumberOperatorResult(Context context, JPushMessage jPushMessage) {
+        super.onMobileNumberOperatorResult(context, jPushMessage);
+    }
+
+    public void startActivity(Context context, NotificationMessage notificationMessage) {
+        LogUtils.e(notificationMessage.notificationExtras);
+        JSONObject jsonObject;
+        try {
+            jsonObject = new JSONObject(notificationMessage.notificationExtras);
+//            memo = jsonObject.getString("memo");
+//            Log.i("JPushMessageReceiver","memo:"+memo);
+        } catch (JSONException e) {
+            e.printStackTrace();
+        }
+
+
+//        MainActivity mainActivity = MainActivity.instance;
+//        if (ActivityManager.getInstance().isOpenActivity(MainActivity.class)&&mainActivity != null) {
+//            mainActivity.startActivity(memo);
+//            LOG.e("OpenActivity");
+//        } else {
+//            Intent i = new Intent(context, MainActivity.class);
+//            i.putExtra("memo", memo);
+//            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
+//            context.startActivity(i);
+//            LOG.e("startActivity");
+//        }
+    }
+
+}

+ 7 - 0
student/src/main/java/com/cooleshow/student/push/PushService.java

@@ -0,0 +1,7 @@
+package com.cooleshow.student.push;
+
+import cn.jpush.android.service.JCommonService;
+
+public class PushService extends JCommonService {
+
+}

+ 41 - 0
student/src/main/java/com/cooleshow/student/push/SealNotificationReceiver.java

@@ -0,0 +1,41 @@
+
+package com.cooleshow.student.push;
+
+import android.content.Context;
+import android.os.Build;
+
+import io.rong.push.PushType;
+import io.rong.push.notification.PushMessageReceiver;
+import io.rong.push.notification.PushNotificationMessage;
+
+public class SealNotificationReceiver extends PushMessageReceiver {
+
+    @Override
+    public boolean onNotificationMessageArrived(Context context, PushType pushType, PushNotificationMessage pushNotificationMessage) {
+        return false;// 返回 false, 会弹出融云 SDK 默认通知; 返回 true, 融云 SDK 不会弹通知, 通知需要由您自定义。
+    }
+
+    @Override
+    public boolean onNotificationMessageClicked(Context context, PushType pushType, PushNotificationMessage notificationMessage) {
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
+            return false;
+        }
+        try {
+//            if (ActivityManager.getInstance().isOpenActivity(MainActivity.class)) {
+//                MainActivity mainActivity = MainActivity.instance;
+//                if (mainActivity != null) {
+//                    mainActivity.startActivity("rongIM");
+//                }
+//            } else {
+//                Intent i = new Intent(context, HtmlActivity.class);
+//                i.putExtra("memo", "rongIM");
+//                i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
+//                context.startActivity(i);
+//            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return false;// 返回 false, 会走融云 SDK 默认处理逻辑, 即点击该通知会打开会话列表或会话界面; 返回 true, 则由您自定义处理逻辑。
+    }
+}

+ 8 - 0
student/src/main/java/com/cooleshow/student/push/XiaomiRongYunReceiver.java

@@ -0,0 +1,8 @@
+package com.cooleshow.student.push;
+
+import io.rong.push.platform.mi.MiMessageReceiver;
+
+public class XiaomiRongYunReceiver extends MiMessageReceiver {
+
+
+}

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

@@ -17,6 +17,7 @@ import androidx.fragment.app.Fragment;
 
 import com.alibaba.android.arouter.facade.annotation.Route;
 import com.common.im.ui.MessageFragment;
+import com.cooleshow.base.common.BaseApplication;
 import com.cooleshow.base.constanst.LoginStatusConstants;
 import com.cooleshow.base.event.LoginStatusEvent;
 import com.cooleshow.base.router.RouterPath;
@@ -44,6 +45,7 @@ import org.greenrobot.eventbus.ThreadMode;
 
 import java.util.ArrayList;
 
+import cn.jpush.android.api.JPushInterface;
 import io.rong.imkit.manager.UnReadMessageManager;
 import io.rong.imlib.RongIMClient;
 
@@ -65,6 +67,7 @@ public class MainActivity extends BaseMVPActivity<ActivityMainBinding, MainPrese
     private TextView tvMsgCount;
     private static final int EXIT_APP_DELAY = 1000;
     private long lastTime = 0;
+    private boolean isNeedSetPushId = true;
 
     /**
      * 打开首页并选中指定tab
@@ -236,6 +239,7 @@ public class MainActivity extends BaseMVPActivity<ActivityMainBinding, MainPrese
     public void loadEventBus(LoginStatusEvent event) {
         if (event != null && event.eventCode == LoginStatusConstants.LOGIN_OUT) {
             IMManager.getInstance().logout();
+            isNeedSetPushId = true;
             LogUtils.i("pq", "LoginStatusEvent:logout");
         }
     }
@@ -248,6 +252,16 @@ public class MainActivity extends BaseMVPActivity<ActivityMainBinding, MainPrese
         //存储userInfo信息
         UserHelper.saveUserInfo(userInfo);
         connectIM();
+        bindPushId();
+    }
+
+    private void bindPushId() {
+        if (isNeedSetPushId && UserHelper.isLogin() && !TextUtils.isEmpty(UserHelper.getUserId())) {
+            String userId = UserHelper.getUserId();
+            LogUtils.i("pq", "registrationId:" + BaseApplication.registrationId);
+            JPushInterface.setAlias(getApplicationContext(), 1, userId);
+            isNeedSetPushId = false;
+        }
     }
 
     @Override