From b48b2ecc0882fb68ae0c6bd631bb5b913fe1428c Mon Sep 17 00:00:00 2001
From: wjc <1243177876@qq.com>
Date: 星期三, 03 十二月 2025 17:38:40 +0800
Subject: [PATCH] 2025年12月03日17:37:56 集成小米商厂

---
 app/src/main/java/com/hdl/photovoltaic/HDLApp.java |  159 +++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 148 insertions(+), 11 deletions(-)

diff --git a/app/src/main/java/com/hdl/photovoltaic/HDLApp.java b/app/src/main/java/com/hdl/photovoltaic/HDLApp.java
index db24c47..bb99acf 100644
--- a/app/src/main/java/com/hdl/photovoltaic/HDLApp.java
+++ b/app/src/main/java/com/hdl/photovoltaic/HDLApp.java
@@ -1,13 +1,13 @@
 package com.hdl.photovoltaic;
 
 import android.app.Activity;
-import android.app.ActivityManager;
-import android.app.AlarmManager;
 import android.app.Application;
-import android.app.PendingIntent;
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
 import android.content.Context;
 import android.content.Intent;
 import android.content.res.Configuration;
+import android.graphics.Color;
 import android.os.Build;
 import android.os.Handler;
 import android.os.LocaleList;
@@ -19,6 +19,14 @@
 
 import androidx.multidex.MultiDex;
 
+import com.alibaba.sdk.android.push.CloudPushService;
+import com.alibaba.sdk.android.push.CommonCallback;
+import com.alibaba.sdk.android.push.noonesdk.PushInitConfig;
+import com.alibaba.sdk.android.push.noonesdk.PushServiceFactory;
+import com.alibaba.sdk.android.push.register.MiPushRegister;
+import com.google.android.gms.common.ConnectionResult;
+import com.google.android.gms.common.GoogleApiAvailability;
+import com.google.firebase.messaging.FirebaseMessaging;
 import com.google.gson.Gson;
 import com.hdl.hdlhttp.HxHttpConfig;
 import com.hdl.linkpm.sdk.HDLLinkPMSdk;
@@ -29,6 +37,7 @@
 import com.hdl.photovoltaic.config.AppConfigManage;
 import com.hdl.photovoltaic.config.ConstantManage;
 import com.hdl.photovoltaic.config.UserConfigManage;
+import com.hdl.photovoltaic.enums.Languages;
 import com.hdl.photovoltaic.enums.LogoutType;
 import com.hdl.photovoltaic.enums.LowerTagType;
 import com.hdl.photovoltaic.enums.NetworkType;
@@ -44,6 +53,7 @@
 import com.hdl.photovoltaic.ui.StartActivity;
 import com.hdl.photovoltaic.uni.HDLUniMPSDKManager;
 import com.hdl.photovoltaic.utils.AppManagerUtils;
+import com.hdl.photovoltaic.utils.BadgeUtils;
 import com.hdl.photovoltaic.utils.LocalManageUtil;
 import com.hdl.photovoltaic.utils.NetworkUtils;
 import com.hdl.photovoltaic.utils.SharedPreUtils;
@@ -101,7 +111,7 @@
 
 //        // 鑾峰彇褰撳墠杩涚▼鐨凱ID
 //        String processMessage = "杩涚▼Uid:" + Process.myUid() + "杩涚▼ID:" + Process.myPid() + " 杩涚▼鍚嶏細" + RuningAcitvityUtil.getAppName(getBaseContext());
-//        Log.d("=======", processMessage);
+        Log.d("Application==onCreate", "onCreate");
 //        Log.d(TAG, processMessage);
 //        if (RuningAcitvityUtil.getAppName(getBaseContext()).contains(":")) {
 //            //闈炲師鐢熻繘绋嬶紝鐢ㄥ垵濮嬪寲鍚庨潰鐨�
@@ -111,7 +121,7 @@
         SharedPreUtils.init(this);
         getAppLanguage();
         //棰勫垱寤鸿剼鏈琷son鏂囦欢澶�
-        HdlFileLogic.getInstance().createHdlESLocalJsonDirectory();
+        HdlFileLogic.getInstance().createHdlDeviceModelLocalJsonDirectory();
         init();
 
 
@@ -122,10 +132,12 @@
         if (TextUtils.isEmpty(language)) {
             //浠庡唴瀛橀噷闈㈣幏鍙栦笉鍒拌瑷�,鑾峰彇褰撳墠绯荤粺鐨�;
             String str = getResources().getConfiguration().locale.getLanguage();
-            if (str.equals(LocalManageUtil.zh)) {
-                UserConfigManage.getInstance().setCurrentAppLanguage(LocalManageUtil.zh);
+            if (str.equals(Languages.zh)) {
+                UserConfigManage.getInstance().setCurrentAppLanguage(Languages.zh);
+            } else if (str.equals(Languages.ar)) {
+                UserConfigManage.getInstance().setCurrentAppLanguage(Languages.ar);
             } else {
-                UserConfigManage.getInstance().setCurrentAppLanguage(LocalManageUtil.en);
+                UserConfigManage.getInstance().setCurrentAppLanguage(Languages.en);
             }
         }
     }
@@ -182,6 +194,16 @@
         initAutoSize();
 //        //鍒濆鍖栨瀬鍏夋帹閫�
 //        initJPush();
+//        //璋锋瓕鍘熺敓fcm鎺ㄩ��
+//        // 妫�鏌� Google Play Services 鍚庡啀鍒濆鍖� FCM
+//        if (isGooglePlayServicesAvailable(this)) {
+//            initFCM();
+//        } else {
+//            HdlLogLogic.print("Google Play Services 涓嶅彲鐢紝鏃犳硶浣跨敤 FCM", true);
+//            // 鍙互鍦ㄨ繖閲屽垵濮嬪寲澶囬�夋帹閫佹柟妗堬紙濡傞樋閲屼簯鑷缓閫氶亾锛�
+//        }
+        //闃块噷浜戞帹閫�
+        initAliYunPush();
         initHDLLinkPMSdk();
         HDLLinkLocalSdk.getInstance().init(getInstance());
         initSocket();
@@ -195,6 +217,42 @@
 //        //鍒濆鍖栧弸鐩烻DK锛屾斁鍦⊿tartActivity閲岄潰鍒濆鍖�
 //        initUMengSDK();
 
+
+    }
+
+    /**
+     * 鍒濆鍖栭樋閲屼簯鎺ㄩ��
+     */
+    private void initAliYunPush() {
+        PushInitConfig pushInitConfig = new PushInitConfig.Builder()
+                .application(this)
+                .appKey("335628427") //璇峰~鍐欎綘鑷繁鐨刟ppKey锛屼簯绔粰鐨�
+                .appSecret("fd1dabe7ec494c878a5970d8646c83bc") //璇峰~鍐欎綘鑷繁鐨刟ppSecret,浜戠缁欑殑
+                .build();
+        PushServiceFactory.init(pushInitConfig);
+        CloudPushService pushService = PushServiceFactory.getCloudPushService();
+        pushService.register(this, new CommonCallback() {
+            @Override
+            public void onSuccess(String success) {
+                String deviceId = pushService.getDeviceId();
+                Log.d("com.aliyun.emas.pocdemo", "鑾峰彇deviceId " + deviceId);
+                saveToken(deviceId);
+
+            }
+
+            @Override
+            public void onFailed(String errorCode, String errorMessage) {
+                //閿欒鐮佽繛鎺ワ細https://help.aliyun.com/document_detail/434686.html?spm=a2c4g.11186623.0.0.62d3556dC2DqKJ#topic-1824037
+                Log.d("com.aliyun.emas.pocdemo", "鍒濆鍖栧け璐�,閿欒鐮�: " + errorCode + "閿欒淇℃伅: " + errorMessage);
+
+            }
+        });
+        if (AppConfigManage.isDebug()) {
+            //浠呴�傜敤浜嶥ebug鍖咃紝姝e紡鍖呬笉闇�瑕佹琛�
+            pushService.setLogLevel(CloudPushService.LOG_DEBUG);
+        }
+        //灏忕背
+        MiPushRegister.register(this, "2882303761520382032", "5612038223032");
 
     }
 
@@ -216,7 +274,6 @@
      * 鍒濆鍖朒DLLinkPMSdk
      */
     private void initHDLLinkPMSdk() {
-        Log.d("===1====", "2222222");
         //1.鍒濆鍖朣DK
         HDLLinkPMSdk.initWithAppKey(this, AppConfigManage.getAppKey(), AppConfigManage.getAppSecret(), AppConfigManage.getAPPRegionUrl());
         //2.璁剧疆鎵撳嵃
@@ -224,7 +281,7 @@
 
         if (TextUtils.isEmpty(UserConfigManage.getInstance().getCurrentAppLanguage())) {
             //榛樿閰嶇疆鎺ュ彛璇锋眰璇█鏄嫳鏂�
-            UserConfigManage.getInstance().setCurrentAppLanguage(LocalManageUtil.en);
+            UserConfigManage.getInstance().setCurrentAppLanguage(Languages.en);
         }
         //3.閰嶇疆鎺ュ彛璇锋眰璇█
         HDLLinkPMSdk.setLanguage(UserConfigManage.getInstance().getCurrentAppLanguage());
@@ -245,6 +302,8 @@
                     new Handler().postDelayed(new Runnable() {
                         @Override
                         public void run() {
+                            BadgeUtils.cancelAllNotifications(getApplicationContext());
+                            BadgeUtils.clearBadge(getApplicationContext());
                             //鍒囨崲鏈嶅姟鍣ㄥ湴鍧�鐢ㄧ殑
                             UserConfigManage.getInstance().setOnlineServer(!UserConfigManage.getInstance().isOnlineServer());
                             UserConfigManage.getInstance().Save();
@@ -256,6 +315,8 @@
                     new Handler().postDelayed(new Runnable() {
                         @Override
                         public void run() {
+                            BadgeUtils.cancelAllNotifications(getApplicationContext());
+                            BadgeUtils.clearBadge(getApplicationContext());
                             restartApp(mHDLApp);
                         }
                     }, 500);
@@ -289,6 +350,8 @@
                     }
                     SystemClock.sleep(200);
                     initDCUniMPSDK();
+                    BadgeUtils.cancelAllNotifications(getApplicationContext());
+                    BadgeUtils.clearBadge(getApplicationContext());
                     Intent intent = new Intent(getInstance(), LoginActivity.class);
                     intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                     startActivity(intent);
@@ -331,6 +394,8 @@
                     }
                     SystemClock.sleep(200);
                     initDCUniMPSDK();
+                    BadgeUtils.cancelAllNotifications(getApplicationContext());
+                    BadgeUtils.clearBadge(getApplicationContext());
                     Intent intent = new Intent(getInstance(), LoginActivity.class);
                     intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                     if (type == 1) {
@@ -410,6 +475,56 @@
 //        JPushInterface.setDebugMode(true);
 //        JPushInterface.init(getBaseContext());
     }
+
+    private void initFCM() {
+        // 鑾峰彇 FCM Token
+        FirebaseMessaging.getInstance().getToken()
+                .addOnCompleteListener(task -> {
+                    if (!task.isSuccessful()) {
+                        Log.w("FCM", "鑾峰彇 FCM Token 澶辫触", task.getException());
+                        return;
+                    }
+                    // 鑾峰彇鏂扮殑 FCM Token
+                    String token = task.getResult();
+                    Log.d("FCM", "FCM Token: " + token);
+
+                    // 淇濆瓨 token
+                    saveToken(token);
+                });
+
+//        // 璁㈤槄涓婚锛堝彲閫夛級
+//        FirebaseMessaging.getInstance().subscribeToTopic("all_users")
+//                .addOnCompleteListener(task -> {
+//                    String msg = "璁㈤槄涓婚鎴愬姛";
+//                    if (!task.isSuccessful()) {
+//                        msg = "璁㈤槄涓婚澶辫触";
+//                    }
+//                    Log.d("FCM", msg);
+//                });
+    }
+
+    /**
+     * 妫�鏌� Google Play Services 鏄惁鍙敤
+     */
+    private boolean isGooglePlayServicesAvailable(Context context) {
+        GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();
+        int resultCode = googleApiAvailability.isGooglePlayServicesAvailable(context);
+        return resultCode == ConnectionResult.SUCCESS;
+    }
+
+    /**
+     * 淇濆瓨浠ょ墝
+     *
+     * @param token 浠ょ墝
+     */
+    public void saveToken(String token) {
+        if (TextUtils.isEmpty(token.trim())) {
+            return;
+        }
+        UserConfigManage.getInstance().setPushToken(token);
+        UserConfigManage.getInstance().Save();
+    }
+
 
     /**
      * 鐩戝惉缃戠粶鐘舵�佸彉鍖�
@@ -537,7 +652,29 @@
             return this;
         }
     }
-
+//    private void createNotificationChannel() {
+//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+//            NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
+//            // 閫氱煡娓犻亾鐨刬d銆�
+//            String id = "ali_push_channel";
+//            // 鐢ㄦ埛鍙互鐪嬪埌鐨勯�氱煡娓犻亾鐨勫悕瀛椼��
+//            CharSequence name = "notification channel";
+//            // 鐢ㄦ埛鍙互鐪嬪埌鐨勯�氱煡娓犻亾鐨勬弿杩般��
+//            String description = "notification description";
+//            int importance = NotificationManager.IMPORTANCE_HIGH;
+//            NotificationChannel mChannel = new NotificationChannel(id, name, importance);
+//            // 閰嶇疆閫氱煡娓犻亾鐨勫睘鎬с��
+//            mChannel.setDescription(description);
+//            // 璁剧疆閫氱煡鍑虹幇鏃剁殑闂伅锛堝鏋淎ndroid璁惧鏀寔鐨勮瘽锛夈��
+//            mChannel.enableLights(true);
+//            mChannel.setLightColor(Color.RED);
+//            // 璁剧疆閫氱煡鍑虹幇鏃剁殑闇囧姩锛堝鏋淎ndroid璁惧鏀寔鐨勮瘽锛夈��
+//            mChannel.enableVibration(true);
+//            mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
+//            // 鏈�鍚庡湪notificationmanager涓垱寤鸿閫氱煡娓犻亾銆�
+//            mNotificationManager.createNotificationChannel(mChannel);
+//        }
+//    }
 
     /**
      * 閲嶅惎app

--
Gitblit v1.8.0