From 2744dfb7867000f044c60fe4ee9103ad51532b9b Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期三, 10 一月 2024 18:12:39 +0800
Subject: [PATCH] 2024年01月10日18:12:32
---
app/src/main/java/com/hdl/photovoltaic/HDLApp.java | 153 ++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 128 insertions(+), 25 deletions(-)
diff --git a/app/src/main/java/com/hdl/photovoltaic/HDLApp.java b/app/src/main/java/com/hdl/photovoltaic/HDLApp.java
index 4514325..85f9657 100644
--- a/app/src/main/java/com/hdl/photovoltaic/HDLApp.java
+++ b/app/src/main/java/com/hdl/photovoltaic/HDLApp.java
@@ -1,16 +1,18 @@
package com.hdl.photovoltaic;
import android.app.Application;
-import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
-import android.content.ServiceConnection;
-import android.content.res.Configuration;
-import android.content.res.Resources;
-import android.os.IBinder;
+import android.content.pm.PackageManager;
+import android.location.Location;
+import android.location.LocationListener;
+import android.location.LocationManager;
+import android.os.Bundle;
import android.text.TextUtils;
-import android.util.DisplayMetrics;
+
+import androidx.annotation.NonNull;
+import androidx.core.app.ActivityCompat;
import com.hdl.hdlhttp.HxHttpConfig;
import com.hdl.linkpm.sdk.HDLLinkPMSdk;
@@ -18,21 +20,25 @@
import com.hdl.linkpm.sdk.user.callback.IOnReloginListener;
import com.hdl.linkpm.sdk.utils.HDLSDKSPUtils;
import com.hdl.photovoltaic.config.AppConfigManage;
+import com.hdl.photovoltaic.config.ConstantManage;
import com.hdl.photovoltaic.config.UserConfigManage;
-import com.hdl.photovoltaic.internet.HttpServer.MyNanoHttpServer;
-import com.hdl.photovoltaic.internet.HttpServer.MyNanoHttpService;
-import com.hdl.photovoltaic.other.HdlFileLogic;
+import com.hdl.photovoltaic.enums.NetworkType;
+import com.hdl.photovoltaic.other.HdlLogLogic;
import com.hdl.photovoltaic.other.HdlOtaLogic;
import com.hdl.photovoltaic.other.HdlThreadLogic;
import com.hdl.photovoltaic.ui.HomeLoginActivity;
import com.hdl.photovoltaic.uni.HDLUniMPSDKManager;
import com.hdl.photovoltaic.utils.AppManagerUtils;
import com.hdl.photovoltaic.utils.LocalManageUtil;
+import com.hdl.photovoltaic.utils.NetworkUtils;
import com.hdl.photovoltaic.utils.SharedPreUtils;
import com.hdl.sdk.link.HDLLinkLocalSdk;
+import com.hdl.sdk.link.core.bean.eventbus.BaseEventBus;
import com.hdl.sdk.link.core.connect.HDLUdpConnect;
import com.hdl.sdk.link.core.utils.QueueUtils;
import com.hdl.sdk.link.core.utils.mqtt.MqttRecvClient;
+
+import org.greenrobot.eventbus.EventBus;
import java.util.HashMap;
import java.util.Locale;
@@ -40,6 +46,7 @@
import cn.jpush.android.api.JPushInterface;
import io.dcloud.common.util.RuningAcitvityUtil;
+import io.dcloud.common.util.net.NetWork;
import okhttp3.logging.HttpLoggingInterceptor;
public class HDLApp extends Application {
@@ -66,6 +73,8 @@
SharedPreUtils.init(this);
getAppLanguage();
initThirdSDK();
+// appLocationInfo();
+
}
public void getAppLanguage() {
@@ -74,7 +83,7 @@
//浠庡唴瀛橀噷闈㈣幏鍙栦笉鍒拌瑷�,鑾峰彇褰撳墠绯荤粺鐨�;
String str = getResources().getConfiguration().locale.getCountry();
if (str.equals("CN") || str.equals("TW")) {
- UserConfigManage.getInstance().setCurrentAppLanguage(LocalManageUtil.zh);
+ UserConfigManage.getInstance().setCurrentAppLanguage(LocalManageUtil.cn);
} else {
UserConfigManage.getInstance().setCurrentAppLanguage(LocalManageUtil.en);
}
@@ -103,6 +112,10 @@
return "";
}
+ public void removeKey(String key) {
+ mInfoMap.remove(key);
+ }
+
/**
* 鍒濆鍖栦笁鏂圭浉鍏砈DK
*/
@@ -120,23 +133,27 @@
// CrashReport.initCrashReport(this, Constant.BUGLY_APP_ID, true);
//6.鍒濆鍖朌CUniMPSDK
initDCUniMPSDK();
-
+// this.initUniMqtt();//濡傛灉鏄儴缃插埌/鎵嬫満涓婃寮忎娇鐢紝娉ㄩ噴鎺夎繖琛屼唬鐮佸氨鍙�
// //7.鍒濆鍖栬嚜瀹氫箟IconToast
// ToastUtils.getInstance().initIconToast(this);
// //8.瀵筬astjson杩涜璁剧疆锛岃В鍐砯astjosn杞崲鎴愬瓧绗︿覆鏃堕瀛楁瘝澶у皬鍐欓棶棰�
// TypeUtils.compatibleWithFieldName = true;
// //9.鍒濆鍖栫綉缁滃伐鍏�
// NetWorkUtil.init(this);
-// //10.鍒濆鍖栨瀬鍏夋帹閫�
+ //鍒濆鍖栨瀬鍏夋帹閫�
initJPush();
initHDLLinkPMSdk();
HDLLinkLocalSdk.getInstance().init(getInstance());
initSocket();
//4.鍒濆鍖朞KHttpLog 鏄惁寮�鍚�
setOKHttpLogOpen(isLogEnabled);
-
+ //鐩戝惉缃戠粶鐘舵�佸彉鍖�
+ this.networkMonitoring();
+ //鍒濆鍖栨湰鍦癮ssets鏂囦欢澶硅祫婧愭枃浠�
+ this.initLocalAssetsData();
}
+
/**
* 鍒濆鍖朒DLLinkPMSdk
@@ -223,19 +240,105 @@
}
+ /**
+ * 鐩戝惉缃戠粶鐘舵�佸彉鍖�
+ */
+ private void networkMonitoring() {
+ NetworkUtils.init(getInstance());
+ NetworkUtils.registerNetworkStatusChangedListener(new NetworkUtils.OnNetworkStatusChangedListener() {
+ @Override
+ public void onDisconnected() {
+ BaseEventBus baseEventBus = new BaseEventBus();
+ baseEventBus.setTopic(ConstantManage.network_change_post);
+ baseEventBus.setType(NetworkType.no_network.toString());
+ baseEventBus.setData("褰撳墠鏃犵綉缁滆繛鎺�");
+ EventBus.getDefault().post(baseEventBus);
+ }
-// /**
-// * 鍒濆鍖杣ni app mqtt
-// */
-// private void initUniMqtt() {
-// try {
-// Through.getInstance().setUni(false);
-// //IP 鍦板潃瑕佹牴鎹疄闄呯殑鏇存敼
-// UniAppMqtt.getInstance().initMqtt(this, "tcp://192.168.3.124:1883", "Android_" + android.os.Build.BRAND + "_" + this.hashCode(), new String[]{"PCToAndroid/#"});
-// } catch (Exception e) {
-// LogUtils.e("娴嬭瘯Mqtt杩炴帴鏈嶅姟绔け璐�");
-// }
-// }
+ @Override
+ public void onConnected(NetworkUtils.NetworkType networkType) {
+ BaseEventBus mobile_network = new BaseEventBus();
+ mobile_network.setTopic(ConstantManage.network_change_post);
+ mobile_network.setType(networkType.toString());
+ mobile_network.setData("姝e湪浣跨敤2G/3G/4G缃戠粶/wifi");
+ EventBus.getDefault().post(mobile_network);
+ }
+ });
+ }
+
+
+ /**
+ * 璇诲彇鍔犺浇鏈湴閰嶇疆鏂囦欢鏁版嵁
+ */
+ private void initLocalAssetsData() {
+ //鏁版嵁澶氭湁鐐瑰崱,鎵�浠ュ姞浜嗙嚎绋�
+ HdlThreadLogic.runSubThread(new Runnable() {
+ @Override
+ public void run() {
+ //鑾峰彇鍥藉鐪佸競鏁版嵁
+ LocalManageUtil.getLocationInfo(getInstance());
+ //鑾峰彇缁忕含搴�
+ LocalManageUtil.getLongLatInfo(getInstance());
+ }
+ });
+
+
+ }
+
+
+ /**
+ * 鍒濆鍖杣ni app mqtt
+ */
+ private void initUniMqtt() {
+ try {
+ String ip = NetworkUtils.getIPAddress(this);
+ if (TextUtils.isEmpty(ip)) {
+ return;
+ }
+ //IP 鍦板潃瑕佹牴鎹疄闄呯殑鏇存敼
+ com.hdl.photovoltaic.ui.test.UniAppMqtt.getInstance().initMqtt(this, "tcp://" + ip + ":1883", "Android_" + android.os.Build.BRAND + "_" + this.hashCode(), new String[]{"PCToAndroid/#"});
+ com.hdl.photovoltaic.ui.test.UniAppMqtt.getInstance().setUni(true);
+ } catch (Exception e) {
+ HdlLogLogic.print("娴嬭瘯Mqtt杩炴帴鏈嶅姟绔け璐�--->");
+ }
+ }
+
+ public void appLocationInfo() {
+ LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
+ if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
+ // TODO: Consider calling
+ // ActivityCompat#requestPermissions
+ // here to request the missing permissions, and then overriding
+ // public void onRequestPermissionsResult(int requestCode, String[] permissions,
+ // int[] grantResults)
+ // to handle the case where the user grants the permission. See the documentation
+ // for ActivityCompat#requestPermissions for more details.
+ return;
+ }
+ //寮�濮嬪畾浣嶆湇鍔★紝minTimeMs鏈�灏忔椂闂撮棿闅旓紙鍗曚綅涓烘绉掞級,minDistanceM鏈�灏忚窛绂婚棿闅旓紙鍗曚綅涓虹背锛夈�佹渶灏忔椂闂撮棿闅旓紙鍗曚綅涓烘绉掞級绛夊弬鏁般��
+ locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, new LocationListener() {
+ @Override
+ public void onLocationChanged(@NonNull Location location) {
+ // 褰撲綅缃彂鐢熷彉鍖栨椂璋冪敤姝ゆ柟娉�
+ double latitude = location.getLatitude(); // 鑾峰彇绾害
+ double longitude = location.getLongitude(); // 鑾峰彇缁忓害
+
+ HdlLogLogic.print("绾害--->" + latitude, true);
+ HdlLogLogic.print("缁忓害--->" + longitude, true);
+ // 杩欓噷鍙互鏍规嵁闇�姹傚鐞嗚幏鍙栧埌鐨勭粡绾害鏁版嵁
+ }
+
+ public void onStatusChanged(String provider, int status, Bundle extras) {
+ }
+
+ public void onProviderEnabled(String provider) {
+ }
+
+ public void onProviderDisabled(String provider) {
+ }
+
+ });
+ }
}
--
Gitblit v1.8.0