From cdf49871675e42a5576f725a93eec7ca15294c6f Mon Sep 17 00:00:00 2001
From: wjc <1243177876@qq.com>
Date: 星期二, 15 四月 2025 17:22:34 +0800
Subject: [PATCH] Merge branch '1.5.2'

---
 app/src/main/java/com/hdl/photovoltaic/utils/GPSManagerUtils.java |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 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 d9b4541..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,15 +4,19 @@
 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;
@@ -36,6 +40,27 @@
         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;
+    }
+
     /**
      * 寮�鍚畾浣�
      */

--
Gitblit v1.8.0