yangyang 3 týždňov pred
rodič
commit
b3b4915c17

+ 9 - 0
app/src/main/java/com/narutohuo/xindazhou/XinDaZhouApplication.kt

@@ -2,6 +2,7 @@ package com.narutohuo.xindazhou
 
 import android.app.Application
 import com.narutohuo.xindazhou.launch.AppInitializer
+import com.narutohuo.xindazhou.push.factory.PushServiceFactory
 
 /**
  * 应用程序入口
@@ -13,6 +14,14 @@ class XinDaZhouApplication : Application() {
         
         // 统一初始化所有模块
         AppInitializer.init(this)
+        PushServiceFactory.init(
+            context = this,
+            // 页面映射规则(用于自动跳转,作为静态配置的补充)
+            // 注意:如果已在 ActivityMapping 中配置,这里可以不传
+            pageMappings = mapOf(
+                "home" to MainActivity::class.java,       // 首页
+            )
+        )
     }
 }
 

+ 40 - 19
capability-push/src/main/AndroidManifest.xml

@@ -75,25 +75,25 @@
             tools:replace="android:value" />
         
         <!-- 极光推送服务(官方 SDK 自带,必须声明) -->
-        <service
-            android:name="cn.jpush.android.service.PushService"
-            android:enabled="true"
-            android:exported="false">
-            <intent-filter>
-                <action android:name="cn.jpush.android.intent.PushService" />
-            </intent-filter>
-        </service>
-        
-        <!-- 极光推送接收器(官方 SDK 自带,必须声明) -->
-        <receiver
-            android:name="cn.jpush.android.service.PushReceiver"
-            android:enabled="true"
-            android:exported="false">
-            <intent-filter>
-                <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY" />
-                <category android:name="android.intent.category.DEFAULT" />
-            </intent-filter>
-        </receiver>
+<!--        <service-->
+<!--            android:name="cn.jpush.android.service.PushService"-->
+<!--            android:enabled="true"-->
+<!--            android:exported="false">-->
+<!--            <intent-filter>-->
+<!--                <action android:name="cn.jpush.android.intent.PushService" />-->
+<!--            </intent-filter>-->
+<!--        </service>-->
+<!--        -->
+<!--        &lt;!&ndash; 极光推送接收器(官方 SDK 自带,必须声明) &ndash;&gt;-->
+<!--        <receiver-->
+<!--            android:name="cn.jpush.android.service.PushReceiver"-->
+<!--            android:enabled="true"-->
+<!--            android:exported="false">-->
+<!--            <intent-filter>-->
+<!--                <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY" />-->
+<!--                <category android:name="android.intent.category.DEFAULT" />-->
+<!--            </intent-filter>-->
+<!--        </receiver>-->
         
         <!-- 自定义消息接收器(封装层,用于业务回调) -->
         <!-- 注意:这是额外的封装层,用于将极光推送的消息回调到业务层 -->
@@ -108,6 +108,27 @@
                 <category android:name="android.intent.category.DEFAULT" />
             </intent-filter>
         </receiver>
+
+        <!-- User defined.  For test only  用户自定义接收消息器,3.0.7开始支持,目前新tag/alias接口设置结果会在该广播接收器对应的方法中回调-->
+        <!--since 5.2.0 接收JPush相关事件-->
+        <receiver android:name=".server.PushMessageService"
+            android:exported="true">
+            <intent-filter>
+                <action android:name="cn.jpush.android.intent.SERVICE_MESSAGE" />
+                <category android:name="com.narutohuo.xindazhou.ble"></category>
+            </intent-filter>
+        </receiver>
+        <!--(jpush|jad)_config_start,jpush和jad公用的组件-->
+        <!-- 可配置android:process参数将PushService放在其他进程中 -->
+        <!--User defined.  For test only 继承自cn.jpush.android.service.JCommonService-->
+        <service
+            android:name=".server.UserService"
+            android:process=":pushcore"
+            android:exported="true">
+            <intent-filter>
+                <action android:name="cn.jiguang.user.service.action" />
+            </intent-filter>
+        </service>
     </application>
 </manifest>
 

+ 98 - 0
capability-push/src/main/java/com/narutohuo/xindazhou/push/server/PushMessageService.kt

@@ -0,0 +1,98 @@
+package com.narutohuo.xindazhou.push.server
+
+import android.content.Context
+import android.content.Intent
+import android.util.Log
+import cn.jpush.android.api.CmdMessage
+import cn.jpush.android.api.CustomMessage
+import cn.jpush.android.api.JPushInterface
+import cn.jpush.android.api.JPushMessage
+import cn.jpush.android.api.NotificationMessage
+import cn.jpush.android.service.JPushMessageReceiver
+import com.google.gson.Gson
+import com.narutohuo.xindazhou.core.log.ILog
+import com.narutohuo.xindazhou.push.factory.PushServiceFactory
+import com.narutohuo.xindazhou.push.impl.PushServiceImpl
+
+class PushMessageService:JPushMessageReceiver(){
+    val TAG: String = "PushMessageService"
+
+    override fun onMessage(context: Context, customMessage: CustomMessage) {
+        Log.e(TAG, "[onMessage] " + customMessage)
+
+    }
+
+    override fun onNotifyMessageOpened(context: Context?, message: NotificationMessage?) {
+        Log.e(TAG, "[onNotifyMessageOpened] " + message)
+
+
+    }
+
+    override fun onMultiActionClicked(context: Context?, intent: Intent) {
+        Log.e(TAG, "[onMultiActionClicked] 用户点击了通知栏按钮")
+        val nActionExtra =
+            intent.getExtras()!!.getString(JPushInterface.EXTRA_NOTIFICATION_ACTION_EXTRA)
+
+        //开发者根据不同 Action 携带的 extra 字段来分配不同的动作。
+        if (nActionExtra == null) {
+            Log.d(TAG, "ACTION_NOTIFICATION_CLICK_ACTION nActionExtra is null")
+            return
+        }
+        if (nActionExtra == "my_extra1") {
+            Log.e(TAG, "[onMultiActionClicked] 用户点击通知栏按钮一")
+        } else if (nActionExtra == "my_extra2") {
+            Log.e(TAG, "[onMultiActionClicked] 用户点击通知栏按钮二")
+        } else if (nActionExtra == "my_extra3") {
+            Log.e(TAG, "[onMultiActionClicked] 用户点击通知栏按钮三")
+        } else {
+            Log.e(TAG, "[onMultiActionClicked] 用户点击通知栏按钮未定义")
+        }
+    }
+
+    override fun onNotifyMessageArrived(context: Context?, message: NotificationMessage?) {
+        Log.e(TAG, "[onNotifyMessageArrived] " + message)
+    }
+
+    override fun onNotifyMessageDismiss(context: Context?, message: NotificationMessage?) {
+        Log.e(TAG, "[onNotifyMessageDismiss] " + message)
+    }
+
+    override fun onRegister(context: Context, registrationId: String?) {
+        Log.e(TAG, "[onRegister] " + registrationId)
+        val intent = Intent("com.jiguang.demo.register")
+        context.sendBroadcast(intent)
+    }
+
+    override fun onConnected(context: Context?, isConnected: Boolean) {
+        Log.e(TAG, "[onConnected] " + isConnected)
+    }
+
+    override fun onCommandResult(context: Context?, cmdMessage: CmdMessage?) {
+        Log.e(TAG, "[onCommandResult] " + cmdMessage)
+    }
+
+    override fun onTagOperatorResult(context: Context?, jPushMessage: JPushMessage?) {
+//        TagAliasOperatorHelper.getInstance().onTagOperatorResult(context, jPushMessage)
+        super.onTagOperatorResult(context, jPushMessage)
+    }
+
+    override fun onCheckTagOperatorResult(context: Context?, jPushMessage: JPushMessage?) {
+//        TagAliasOperatorHelper.getInstance().onCheckTagOperatorResult(context, jPushMessage)
+        super.onCheckTagOperatorResult(context, jPushMessage)
+    }
+
+    override fun onAliasOperatorResult(context: Context?, jPushMessage: JPushMessage?) {
+//        TagAliasOperatorHelper.getInstance().onAliasOperatorResult(context, jPushMessage)
+        super.onAliasOperatorResult(context, jPushMessage)
+    }
+
+    override fun onMobileNumberOperatorResult(context: Context?, jPushMessage: JPushMessage?) {
+//        TagAliasOperatorHelper.getInstance().onMobileNumberOperatorResult(context, jPushMessage)
+        super.onMobileNumberOperatorResult(context, jPushMessage)
+    }
+
+    override fun onNotificationSettingsCheck(context: Context?, isOn: Boolean, source: Int) {
+        super.onNotificationSettingsCheck(context, isOn, source)
+        Log.e(TAG, "[onNotificationSettingsCheck] isOn:" + isOn + ",source:" + source)
+    }
+}

+ 6 - 0
capability-push/src/main/java/com/narutohuo/xindazhou/push/server/UserService.kt

@@ -0,0 +1,6 @@
+package com.narutohuo.xindazhou.push.server
+
+import cn.jpush.android.service.JCommonService
+
+class UserService: JCommonService() {
+}

+ 3 - 3
capability-push/src/main/res/values/strings.xml

@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="utf-8"?>
 <resources>
     <!-- 极光推送基础配置 -->
-    <string name="jpush_app_key">your_jpush_appkey_here</string>
-    <string name="push_jpush_app_key">your_jpush_appkey_here</string>
-    <string name="push_jpush_channel">developer-default</string>
+    <string name="jpush_app_key">5d61ceb7e31a7795753105e4</string>
+    <string name="push_jpush_app_key">5d61ceb7e31a7795753105e4</string>
+    <string name="push_jpush_channel">1000</string>
     
     <!-- 厂商通道配置(可选,提升推送到达率) -->
     <!-- 需要在各厂商开放平台申请 AppKey 和 AppSecret -->