From 87cd5df70918e6ba1af849c5f026d3719bfdb1ac Mon Sep 17 00:00:00 2001
From: wjc <1243177876@qq.com>
Date: 星期三, 09 四月 2025 09:06:29 +0800
Subject: [PATCH] Merge branch '1.5.2' into dev

---
 app/src/main/java/com/hdl/photovoltaic/utils/GPSManagerUtils.java |   46 +++++++++++++++++++++++++++++++++++-----------
 1 files changed, 35 insertions(+), 11 deletions(-)

diff --git a/app/src/main/java/com/hdl/photovoltaic/utils/GPSManagerUtils.java b/app/src/main/java/com/hdl/photovoltaic/utils/GPSManagerUtils.java
index 5c50e1d..6dfb8cc 100644
--- a/app/src/main/java/com/hdl/photovoltaic/utils/GPSManagerUtils.java
+++ b/app/src/main/java/com/hdl/photovoltaic/utils/GPSManagerUtils.java
@@ -4,18 +4,21 @@
 import android.annotation.SuppressLint;
 import android.content.Context;
 import android.content.pm.PackageManager;
+import android.location.Address;
+import android.location.Geocoder;
 import android.location.Location;
 import android.location.LocationListener;
 import android.location.LocationManager;
 import android.os.Bundle;
 
 
-
-
+import java.io.IOException;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.util.List;
+import java.util.Locale;
 
+import androidx.annotation.NonNull;
 import androidx.core.app.ActivityCompat;
 
 import com.hdl.photovoltaic.other.HdlLogLogic;
@@ -37,9 +40,29 @@
         return Singleton.INSTANCE;
     }
 
+    public String getCountryCode(Context context) throws IOException {
+        LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
+        if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
+            // 澶勭悊鏉冮檺璇锋眰
+            return null;
+        }
+        Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
+        if (location == null) {
+            location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
+        }
+        if (location != null) {
+            Geocoder geocoder = new Geocoder(context, Locale.getDefault());
+            List<Address> addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
+            if (addresses != null && !addresses.isEmpty()) {
+                return addresses.get(0).getCountryCode();
+            }
+        }
+
+        return null;
+    }
+
     /**
      * 寮�鍚畾浣�
-     *
      */
     @SuppressLint("MissingPermission")
     public void getLocation(Context context) {
@@ -50,12 +73,12 @@
         //2.鑾峰彇浣嶇疆鎻愪緵鍣紝GPS鎴栨槸NetWork
         List<String> providers = locationManager.getProviders(true);
 //        locationProvider = LocationManager.GPS_PROVIDER;
-        if (providers.contains(LocationManager.NETWORK_PROVIDER)) {
-            //濡傛灉鏄綉缁滃畾浣�
-            locationProvider = LocationManager.NETWORK_PROVIDER;
-        } else if (providers.contains(LocationManager.GPS_PROVIDER)) {
+        if (providers.contains(LocationManager.GPS_PROVIDER)) {
             //濡傛灉鏄疓PS瀹氫綅
             locationProvider = LocationManager.GPS_PROVIDER;
+        } else if (providers.contains(LocationManager.NETWORK_PROVIDER)) {
+            //濡傛灉鏄綉缁滃畾浣�
+            locationProvider = LocationManager.NETWORK_PROVIDER;
         } else {
             return;
         }
@@ -69,7 +92,8 @@
             showLocation(location);
         } else {
             // 鐩戣鍦扮悊浣嶇疆鍙樺寲锛岀浜屼釜鍜岀涓変釜鍙傛暟鍒嗗埆涓烘洿鏂扮殑鏈�鐭椂闂磎inTime鍜屾渶鐭窛绂籱inDistace
-            locationManager.requestLocationUpdates(locationProvider, 60*1000, 10, mListener);
+            //60绉掓洿鐪佺數
+            locationManager.requestLocationUpdates(locationProvider, 30 * 1000, 10, mListener);
         }
     }
 
@@ -84,8 +108,8 @@
             BigDecimal latitude = BigDecimal.valueOf(location.getLatitude());
             String lon = longitude.setScale(6, RoundingMode.HALF_DOWN).doubleValue() + "";
             String lat = latitude.setScale(6, RoundingMode.HALF_DOWN).doubleValue() + "";
-//            HdlLogLogic.print("绾害--->" + lon, false);
-//            HdlLogLogic.print("缁忓害--->" + lat, false);
+            HdlLogLogic.print("绾害--->" + lon, false);
+            HdlLogLogic.print("缁忓害--->" + lat, false);
 //            if(!TextUtils.isEmpty(lon)&&!TextUtils.isEmpty(lat)){
 //                DataController.getInstance().lonLatUpdate(lon,lat,new IResponseCallBack<String>() {
 //                    @Override
@@ -116,7 +140,7 @@
 
         // 濡傛灉浣嶇疆鍙戠敓鍙樺寲锛岄噸鏂版樉绀�
         @Override
-        public void onLocationChanged(Location location) {
+        public void onLocationChanged(@NonNull Location location) {
             showLocation(location);
         }
     };

--
Gitblit v1.8.0