From 2f5411b86c59706d31f6ec7de629d8f860725e46 Mon Sep 17 00:00:00 2001
From: wjc <1243177876@qq.com>
Date: 星期三, 26 十一月 2025 19:56:56 +0800
Subject: [PATCH] 2025年11月26日19:56:45 集成谷歌推送

---
 app/src/main/java/com/hdl/photovoltaic/ui/BPowerStationActivity.java |  223 +++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 191 insertions(+), 32 deletions(-)

diff --git a/app/src/main/java/com/hdl/photovoltaic/ui/BPowerStationActivity.java b/app/src/main/java/com/hdl/photovoltaic/ui/BPowerStationActivity.java
index c1e077a..315f9ab 100644
--- a/app/src/main/java/com/hdl/photovoltaic/ui/BPowerStationActivity.java
+++ b/app/src/main/java/com/hdl/photovoltaic/ui/BPowerStationActivity.java
@@ -20,6 +20,8 @@
 import android.view.View;
 import android.widget.TextView;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.google.gson.Gson;
 import com.google.gson.reflect.TypeToken;
 import com.hdl.linkpm.sdk.core.exception.HDLException;
@@ -42,17 +44,22 @@
 import com.hdl.photovoltaic.other.HdlMessageLogic;
 import com.hdl.photovoltaic.other.HdlMqttLogic;
 import com.hdl.photovoltaic.other.HdlOtaLogic;
+import com.hdl.photovoltaic.other.HdlPushLogic;
 import com.hdl.photovoltaic.other.HdlResidenceLogic;
 import com.hdl.photovoltaic.other.HdlThreadLogic;
 import com.hdl.photovoltaic.other.HdlUniLogic;
+import com.hdl.photovoltaic.push.PushMessageInfoBean;
 import com.hdl.photovoltaic.ui.bean.DeviceRemoteInfo;
+import com.hdl.photovoltaic.ui.bean.MessageBean;
 import com.hdl.photovoltaic.ui.bean.OidBean;
 import com.hdl.photovoltaic.ui.bean.UnCountBean;
 import com.hdl.photovoltaic.ui.home.HomePageFragment;
 import com.hdl.photovoltaic.ui.me.MeFragment;
-import com.hdl.photovoltaic.ui.message.MessageFragment;
+import com.hdl.photovoltaic.ui.message.MessageHouseFragment;
+import com.hdl.photovoltaic.ui.message.MessageInfoActivity;
 import com.hdl.photovoltaic.ui.powerstation.HouseAndDeviceFragment;
 import com.hdl.photovoltaic.uni.HDLUniMP;
+import com.hdl.photovoltaic.uni.HDLUniMPSDKManager;
 import com.hdl.photovoltaic.utils.AppManagerUtils;
 import com.hdl.photovoltaic.utils.GPSManagerUtils;
 import com.hdl.photovoltaic.utils.PermissionUtils;
@@ -68,6 +75,7 @@
 import com.hdl.sdk.link.core.config.HDLLinkConfig;
 import com.hdl.sdk.link.core.connect.HDLUdpConnect;
 import com.hdl.sdk.link.core.utils.mqtt.MqttRecvClient;
+import com.umeng.analytics.MobclickAgent;
 
 import org.greenrobot.eventbus.Subscribe;
 import org.greenrobot.eventbus.ThreadMode;
@@ -75,6 +83,7 @@
 import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;
 
 import cn.jpush.android.api.JPushInterface;
 
@@ -105,7 +114,7 @@
         setStatusBarTranslucent();
         getWindow().setNavigationBarColor(getColor(R.color.text_FF1C1C1E));
         //鍒濆鍖栫鐗�
-        initFragment(savedInstanceState);
+        initFragment(null);
         //鍒濆鍖�
         this.initView();
         //鍒濆鍖栫晫闈㈢洃鍚櫒
@@ -114,10 +123,14 @@
         this.registerAllTopicsListener();
         //鍒濆鍖杕qtt瀹㈡埛绔�
         this.initMqttClient();
-        //涓婁紶鏋佸厜娉ㄥ唽ID鍒颁簯绔�
-        this.pushTokens();
-        //鐐瑰嚮鏋佸厜閫氱煡鏍忔秷鎭繘鏉�
-        this.clickJpushNotificationMessage();
+//        //涓婁紶鏋佸厜娉ㄥ唽ID鍒颁簯绔� 闅愯棌2025-11-21 11:52:27
+//        this.pushTokens();
+        //涓婁紶鎺ㄥ姩浠ょ墝鍒颁簯绔紙璋锋瓕FCM鎺ㄩ�侊級
+        this.sendPushTokenToServer(UserConfigManage.getInstance().getPushToken());
+//        //鐐瑰嚮鏋佸厜閫氱煡鏍忔秷鎭繘鏉�
+//        this.clickJpushNotificationMessage();
+        //鐐瑰嚮閫氱煡鏍忔秷鎭繘鏉�
+        this.OpenSpecifiedPage(getIntent(), "onBindView");
         //鍒濆鍖栨潈闄�
         this.requestPermissions();
         //璇诲彇娑堟伅鏈鏁伴噺
@@ -128,6 +141,36 @@
 
     }
 
+    /**
+     * 鐐瑰嚮閫氱煡鏍忔秷鎭繘鏉�
+     */
+    private void OpenSpecifiedPage(Intent intent, String tag) {
+        Log.d("==========", tag);
+        try {
+            String data = getIntentExpantData(intent);
+            if (TextUtils.isEmpty(data)) {
+                return;
+            }
+            PushMessageInfoBean pushMessageInfoBean = HdlPushLogic.getInstance().pushDataProcessing("", "", data);
+            if (TextUtils.isEmpty(pushMessageInfoBean.getMsgId())) {
+                return;
+            }
+            MessageBean messageBean = new MessageBean();
+            messageBean.setMsgId(Long.valueOf(pushMessageInfoBean.getMsgId()));
+            Intent intentMessageInfoActivity = new Intent();
+            intentMessageInfoActivity.setClass(_mActivity, MessageInfoActivity.class);
+            intentMessageInfoActivity.putExtra("messageBean", JSONObject.toJSONString(messageBean));
+            startActivity(intentMessageInfoActivity);
+            this.clickNotificationMessageTab();
+            if (null != HDLUniMPSDKManager.getInstance().getUniMP()) {
+                Log.d("HDLUniMPSDKManager.getInstance().getUniMP()", "HDLUniMPSDKManager.getInstance().getUniMP()");
+                HDLUniMPSDKManager.getInstance().getUniMP().closeUniMP();
+            }
+
+        } catch (Exception e) {
+            Log.d("閿欒", " " + e.getMessage());
+        }
+    }
 
     /**
      * 鍒濆鍖朏ragment
@@ -139,7 +182,7 @@
         //纰庣墖鍒濆鍖�
         HomePageFragment mHomePageFragment = new HomePageFragment();
         HouseAndDeviceFragment mHouseAndDeviceFragment = new HouseAndDeviceFragment();
-        MessageFragment mMessageFragment = new MessageFragment();
+        MessageHouseFragment mMessageHouseFragment = new MessageHouseFragment();
         MeFragment mMeFragment = new MeFragment();
         if (savedInstanceState != null) {
             //鈥滃唴瀛橀噸鍚�濇椂璋冪敤 鑾峰彇鈥滃唴瀛橀噸鍚�濇椂淇濆瓨鐨勭储寮曚笅鏍�
@@ -151,16 +194,31 @@
             fragmentList.add(mFragmentManager.findFragmentByTag(1 + ""));
             fragmentList.add(mFragmentManager.findFragmentByTag(2 + ""));
             fragmentList.add(mFragmentManager.findFragmentByTag(3 + ""));
-            restoreFragment();//鎭㈠fragment椤甸潰
+            this.restoreFragment();//鎭㈠fragment椤甸潰
         } else {
+            //
+            this.removeAllFragments(mFragmentManager);
             //姝e父鍚姩鏃惰皟鐢�
+            if (!fragmentList.isEmpty()) {
+                fragmentList.clear();
+            }
             fragmentList.add(mHomePageFragment);
             fragmentList.add(mHouseAndDeviceFragment);
-            fragmentList.add(mMessageFragment);
+            fragmentList.add(mMessageHouseFragment);
             fragmentList.add(mMeFragment);
-            showFragment();
+            this.showFragment();
         }
 
+
+//        if (!fragmentList.isEmpty()) {
+//            fragmentList.clear();
+//        }
+//        // 姝e父鍚姩鏃惰皟鐢�
+//        fragmentList.add(mHomePageFragment);
+//        fragmentList.add(mHouseAndDeviceFragment);
+//        fragmentList.add(mMessageFragment);
+//        fragmentList.add(mMeFragment);
+//        FragmentUtils.loadMultipleFragment(R.id.module_fcv, mFragmentManager, fragmentList.toArray(new Fragment[0]));
     }
 
 
@@ -169,6 +227,7 @@
      * 鏄剧ずfragment
      */
     private void showFragment() {
+//        FragmentUtils.showHideFragment(mFragmentManager, fragmentList.toArray(new Fragment[0])[currentFragmentIndex]);
         FragmentTransaction ft = mFragmentManager.beginTransaction();
         //濡傛灉涔嬪墠娌℃湁娣诲姞杩�
         if (!fragmentList.get(currentFragmentIndex).isAdded()) {
@@ -177,12 +236,10 @@
         } else {
             ft.hide(currentFragment).show(fragmentList.get(currentFragmentIndex));
         }
+        //鎶婂綋鍓嶆樉绀虹殑fragment璁板綍涓嬫潵
         currentFragment = fragmentList.get(currentFragmentIndex);
         ft.commit();
         //鎶婂綋鍓嶆樉绀虹殑fragment璁板綍涓嬫潵
-        currentFragment = fragmentList.get(currentFragmentIndex);
-
-
     }
 
     /**
@@ -198,6 +255,28 @@
             }
         }
         ft.commit();
+    }
+
+    private void removeAllFragments(FragmentManager manager) {
+        if (manager == null) return;
+        try {
+            final List<Fragment> fragments = manager.getFragments();
+            if (fragments.isEmpty()) {
+                return;
+            }
+            FragmentTransaction transaction = manager.beginTransaction();
+            for (int i = 0; i < fragments.size(); i++) {
+                Fragment fragment = fragments.get(i);
+                if (fragment != null) {
+//                     FragmentManager childManager = fragment.getChildFragmentManager();
+//                    removeAllFragments(childManager);
+                    transaction.remove(fragment);
+                }
+            }
+            transaction.commit();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
 
     }
 
@@ -243,14 +322,15 @@
                     }
                 }
                 if (!TextUtils.isEmpty(registrationID)) {
-                    UserConfigManage.getInstance().setRegistrationID(registrationID);
-                    UserConfigManage.getInstance().Save();
+//                    UserConfigManage.getInstance().setRegistrationID(registrationID);
+//                    UserConfigManage.getInstance().Save();
                     String finalRegistrationID = registrationID;
                     HdlResidenceLogic.getInstance().pushAdd(new CloudCallBeak<String>() {
                         @Override
                         public void onSuccess(String pushId) {
 
                             if (!TextUtils.isEmpty(pushId)) {
+                                UserConfigManage.getInstance().setPushToken(finalRegistrationID);
                                 UserConfigManage.getInstance().setPushId(pushId);
                                 UserConfigManage.getInstance().Save();
                             }
@@ -269,6 +349,34 @@
                 }
 
 
+            }
+        });
+    }
+
+    /**
+     * 涓婁紶 token 鍒版湇鍔″櫒
+     *
+     * @param token 浠ょ墝
+     */
+    private void sendPushTokenToServer(final String token) {
+        if (TextUtils.isEmpty(token)) {
+            return;
+        }
+        HdlResidenceLogic.getInstance().pushAdd(new CloudCallBeak<String>() {
+            @Override
+            public void onSuccess(String pushId) {
+
+                if (!TextUtils.isEmpty(pushId)) {
+                    UserConfigManage.getInstance().setToken(token);
+                    UserConfigManage.getInstance().setPushId(pushId);
+                    UserConfigManage.getInstance().Save();
+                }
+                HdlLogLogic.print("娣诲姞浠ょ墝鍒颁簯绔� PushToken:" + UserConfigManage.getInstance().getPushToken() + " pushId:" + pushId, true);
+            }
+
+            @Override
+            public void onFailure(HDLException e) {
+                HdlLogLogic.print("娣诲姞浠ょ墝鍒颁簯绔け璐� PushToken:" + UserConfigManage.getInstance().getPushToken() + " 閿欒锛�" + e.getMessage(), true);
             }
         });
     }
@@ -373,6 +481,7 @@
     @Override
     protected void onDestroy() {
         super.onDestroy();
+        Log.d("BPowerStationActivity", "onDestroy");
         HdlUniLogic.getInstance().checkRemoveOtherUniMPEventCallBack();
         //绉婚櫎鐩戝惉
         HDLLinkLocalSdk.getInstance().removeAllTopicsListener(allTopicsListener);
@@ -441,12 +550,12 @@
         this.notificationSet();
         //ACCESS_FINE_LOCATION	鍏佽浣跨敤GPS瀹氫綅
         //ACCESS_COARSE_LOCATION	鍏佽浣跨敤WIFI鐑偣鎴栧熀绔欐潵鑾峰彇绮楃暐鐨勫畾浣�
-//        String[] ary = PermissionUtils.checkPermission(_mActivity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION});
-//        if (ary.length > 0) {
-//            this.requestPermissions(ary, PermissionUtils.STATUS_SUCCESS);
-//        } else {
-//            locationUpdates();
-//        }
+        String[] ary = PermissionUtils.checkPermission(_mActivity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION});
+        if (ary.length > 0) {
+            this.requestPermissions(ary, PermissionUtils.STATUS_SUCCESS);
+        } else {
+            locationUpdates();
+        }
     }
 
     @Override
@@ -539,6 +648,7 @@
                         uniCallBackBaseBean.setData(linkResponse.getData());
                         HdlUniLogic.getInstance().sendUni(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_MODEL, uniCallBackBaseBean);
                         HdlLogLogic.print(linkResponse.getTopic() + new Gson().toJson(linkResponse.getData()), true);
+//                        HdlDeviceLogic.getInstance().searchAllNetworkGateway(null);//閫嗗彉鍣╳ifi鐘舵��-閲嶆柊鎼滅储涓�涓嬮�嗗彉鍣�-閲嶆柊鏇存柊杩炴帴鐘舵��
                     } else if (linkResponse.getTopic().endsWith("/app/thing/event/appHomeRemoveRefresh/up")) {
                         String[] topicArray = linkResponse.getTopic().split("/");
                         //浣忓畢鍒犻櫎閫氱煡
@@ -563,6 +673,17 @@
                         uniCallBackBaseBean.setData(topicArray[1]);
                         HdlUniLogic.getInstance().sendUni(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_MODEL, uniCallBackBaseBean);
                         HdlLogLogic.print(linkResponse.getTopic() + new Gson().toJson(linkResponse.getData()), true);
+                    } else if (linkResponse.getTopic().endsWith("/app/thing/event/appHomeDeliverRollbackRefresh/up")) {
+                        //B绔櫥褰曠數绔欏洖婊氭椂锛屾敹鍒板洖婊氱殑浜嬩欢鏃讹紝鍙戜釜閫氱煡缁檜niapp锛寀niapp鍒锋柊涓嬬數绔欑殑鏉冮檺锛岃皟鏁翠笅鑿滃崟鏍忕殑鍐呭銆�
+                        String[] topicArray = linkResponse.getTopic().split("/");
+                        if (topicArray.length < 2) {
+                            return;
+                        }
+                        final String HomeId = topicArray[2];
+                        HDLUniMP.UniCallBackBaseBean uniCallBackBaseBean = new HDLUniMP.UniCallBackBaseBean();
+                        uniCallBackBaseBean.setType(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_home_delivery_rollback);
+                        uniCallBackBaseBean.setData(HomeId);
+                        HdlUniLogic.getInstance().sendUni(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_MODEL, uniCallBackBaseBean);
                     } else if (linkResponse.getTopic().endsWith("/app/thing/property/send")) {
                         //璁惧鐘舵�佸彉鏇磘opic锛�/user/${homeId}/app/thing/property/send
                         if (linkResponse.getData() == null) {
@@ -624,7 +745,7 @@
                 return;
             }
             int index = -1;
-            List<GatewayBean> list = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(UserConfigManage.getInstance().getHomeId(),null);
+            List<GatewayBean> list = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(UserConfigManage.getInstance().getHomeId());
             for (int i = 0; i < list.size(); i++) {
                 GatewayBean gatewayBean = list.get(i);
                 if (gatewayBean.getGatewayId().equals(topics[2])) {
@@ -693,6 +814,9 @@
                 bottomViewChangeOfStyle();
                 showFragment();
             }
+        } else if (event.getTopic().contains(ConstantManage.refresh_push_token)) {
+            //pushToken鏇存柊
+            sendPushTokenToServer(UserConfigManage.getInstance().getPushToken());
         }
     }
 
@@ -745,19 +869,27 @@
         });
     }
 
+    @Override
+    protected void onNewIntent(Intent intent) {
+        super.onNewIntent(intent);
+        //AndroidManifest.xml 闇�瑕佹坊鍔犲惎鍔ㄦā寮廰ndroid:launchMode="singleTask"鎵嶆墽琛岃繖涓柟娉�
+        OpenSpecifiedPage(intent, "onNewIntent");
+    }
 
     /**
-     * 鐐瑰嚮鏋佸厜閫氱煡鏍忔秷鎭繘鏉�
+     * 鐐瑰嚮閫氱煡鏍忔秷鎭繘鏉�,榛樿閫夋嫨娑堟伅妯″潡
      */
-    private void clickJpushNotificationMessage() {
-        Intent intent = getIntent();
-        if (intent != null) {
-            String key = intent.getStringExtra("skip");
-            if (key != null) {
-                //瑙﹀彂娑堟伅鐐瑰嚮浜嬩欢
-                viewBinding.myMessageBottomIl2.clickTv.performClick();
-            }
-        }
+    private void clickNotificationMessageTab() {
+        //瑙﹀彂娑堟伅鐐瑰嚮浜嬩欢
+        viewBinding.myMessageBottomIl2.clickTv.performClick();
+//        if (currentFragmentIndex == 2) {
+//            return;
+//        }
+//        currentFragmentIndex = 2;
+//        bottomViewChangeOfStyle();
+//        showFragment();
+//        HdlCommonLogic.lowerTagType = LowerTagType.message;
+//        HdlCommonLogic.getInstance().postEventBusSticky(ConstantManage.homepage_title_tab_switch, HomepageTitleTabSwitch.message.toString());
     }
 
 
@@ -785,7 +917,10 @@
                 return;
             } else {
                 AppManagerUtils.getAppManager().finishAllActivity();
+                //濡傛灉寮�鍙戣�呰皟鐢╧ill鎴栬�卐xit涔嬬被鐨勬柟娉曟潃姝昏繘绋嬶紝鎴栬�呭弻鍑籦ack閿細鏉�姝昏繘绋嬶紝璇峰姟蹇呭湪姝や箣鍓嶈皟鐢∕obclickAgent.onKillProcess鏂规硶锛岀敤鏉ヤ繚瀛樼粺璁℃暟鎹��
+                MobclickAgent.onKillProcess(_mActivity);
                 Process.killProcess(Process.myPid());
+
             }
         }
         super.onBackPressed();
@@ -848,5 +983,29 @@
         }
     }
 
+    /**
+     * 澶勭悊浠庨�氱煡鐐瑰嚮甯︽潵鐨勬暟鎹紝杩欓噷鑾峰彇鏁版嵁锛岀劧鍚庨�忎紶缁欎富鐣岄潰鍋氬鐞�
+     *
+     * @return 杩斿洖闄勫姞鏁版嵁
+     */
+    private String getIntentExpantData(Intent intent) {
+        try {
+            if (intent == null) {
+                return "";
+            }
+            // 澶勭悊浠庨�氱煡鐐瑰嚮甯︽潵鐨勬暟鎹紝杩欓噷鑾峰彇鏁版嵁锛岀劧鍚庨�忎紶缁欎富鐣岄潰鍋氬鐞�
+            if (intent.getExtras() != null) {
+                for (String key : intent.getExtras().keySet()) {
+                    if (key.equals("pushData")) {
+                        return Objects.requireNonNull(intent.getExtras().get(key)).toString();
+                    }
+                }
+            }
+        } catch (Exception e) {
+            return "";
+        }
+        return "";
+    }
+
 
 }
\ No newline at end of file

--
Gitblit v1.8.0