leon 1 year ago
parent
commit
825df2efa7

+ 2 - 0
android/app/src/main/AndroidManifest.xml

@@ -10,6 +10,8 @@
     <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
     <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>
     <uses-permission android:name="android.permission.WAKE_LOCK"/>
+    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
+    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
 
     <queries>
       <intent>

File diff suppressed because it is too large
+ 0 - 0
android/app/src/main/assets/index.android.bundle


File diff suppressed because it is too large
+ 0 - 0
android/app/src/main/assets/index.android.map


+ 3 - 1
android/app/src/main/java/com/hola/AlarmReceiver.java

@@ -25,15 +25,17 @@ public class AlarmReceiver extends BroadcastReceiver {
         String categoryId = intent.getStringExtra("categoryId");
         String strId = intent.getStringExtra("id");
         int msg_id = intent.getIntExtra("msg_id",0);
+        Log.i("set alarm status:","收到推送设置");
 
         Intent intent2 = new Intent(context, MainActivity.class);
         count++;
         PendingIntent pendingIntent = PendingIntent.getActivity(context, count, intent2, PendingIntent.FLAG_UPDATE_CURRENT);
         // 创建通知构建器
-        NotificationCompat.Builder builder = new NotificationCompat.Builder(context, strId)
+        NotificationCompat.Builder builder = new NotificationCompat.Builder(context, categoryId)
                 .setSmallIcon(R.drawable.ic_stat_onesignal_default)
                 .setContentTitle(title)
                 .setContentText(message)
+                .setAutoCancel(true)
                 .setPriority(NotificationCompat.PRIORITY_HIGH)
                 .setContentIntent(pendingIntent);
 

+ 124 - 63
android/app/src/main/java/com/hola/HolaModule.java

@@ -9,6 +9,7 @@ import android.app.NotificationManager;
 import android.app.PendingIntent;
 import android.content.Context;
 import android.content.Intent;
+import android.location.LocationManager;
 import android.net.Uri;
 import android.os.Build;
 import android.os.SystemClock;
@@ -19,6 +20,7 @@ import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 
 import com.facebook.react.bridge.Callback;
+import com.facebook.react.bridge.Promise;
 import com.facebook.react.bridge.ReactApplicationContext;
 import com.facebook.react.bridge.ReactContextBaseJavaModule;
 import com.facebook.react.bridge.ReactMethod;
@@ -35,7 +37,7 @@ import java.util.List;
 public class HolaModule extends ReactContextBaseJavaModule {
     private static final String CHANNEL_ID = "local_notification_channel";
     private static final String CHANNEL_NAME = "Daily Reminder";
-    private static final String CHANNEL_DESCRIPTION = "Daily reminder notification at 9:00 AM";
+    private static final String CHANNEL_DESCRIPTION = "Daily reminder notification ";
 
 
     public HolaModule(@Nullable ReactApplicationContext reactContext) {
@@ -73,8 +75,49 @@ public class HolaModule extends ReactContextBaseJavaModule {
         currentActivity.startActivity(intent);
     }
 
+    @ReactMethod
+    public void openSystemLocationSettings() {
+        Activity currentActivity = getCurrentActivity();
+        Context context = getReactApplicationContext();
+        Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
+//        Uri uri = Uri.fromParts("package", context.getPackageName(), null);
+//        intent.setData(uri);
+        currentActivity.startActivity(intent);
+    }
+
+    @ReactMethod
+    public void checkSystemLocationService(Promise promise){
+        Context context = getReactApplicationContext();
+        LocationManager lm = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
+        boolean gps_enabled = false;
+        boolean network_enabled = false;
+
+        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
+            promise.resolve(lm.isLocationEnabled());
+        }
+        else {
+            try {
+                gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
+            } catch(Exception ex) {}
+
+            try {
+                network_enabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
+            } catch(Exception ex) {}
+
+            if (gps_enabled||network_enabled){
+                promise.resolve(true);
+            }
+            else {
+                promise.resolve(false);
+            }
+        }
+    }
+
     @ReactMethod
     public void addLocalPush(String jsonData){
+
+
+
         if (getCurrentActivity()==null){
             return;
         }
@@ -88,11 +131,11 @@ public class HolaModule extends ReactContextBaseJavaModule {
                 String strId = jsonObject.getString("id");
                 String categoryId = jsonObject.getString("category_id");
 
-                createNotificationChannel(getCurrentActivity(),strId);
+                createNotificationChannel(getCurrentActivity(),categoryId);
                 Intent intent = new Intent(getCurrentActivity(), AlarmReceiver.class);
                 intent.putExtra("title", title);
                 intent.putExtra("message", body);
-                intent.putExtra("channel", CHANNEL_ID);
+                intent.putExtra("channel", categoryId);
                 intent.putExtra("id",strId);
                 intent.putExtra("categoryId",categoryId);
                 intent.putExtra("msg_id",i);
@@ -102,14 +145,20 @@ public class HolaModule extends ReactContextBaseJavaModule {
                         getCurrentActivity(), i, intent, android.app.PendingIntent.FLAG_UPDATE_CURRENT);
 
                 AlarmManager alarmManager = (AlarmManager) getCurrentActivity().getSystemService(Context.ALARM_SERVICE);
+
+                AlarmManager.AlarmClockInfo info = alarmManager.getNextAlarmClock();
+                if (info!=null){
+                    long t = info.getTriggerTime();
+                    PendingIntent pt = info.getShowIntent();
+                    String aa = info.toString();
+                }
+
+
                 if (mode.equals("ONCE")){
                     long leftMillis = toNearest1000(jsonObject.getLong("once")-System.currentTimeMillis());
                     if (leftMillis>0){
                         alarmManager.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime()+leftMillis,pendingIntent);
-//                        alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime()+leftMillis,pendingIntent);
                     }
-
-//                    alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime()+10*1000,pendingIntent);
                 }
                 else {
                     JSONObject recurring = jsonObject.getJSONObject("recurring");
@@ -124,32 +173,11 @@ public class HolaModule extends ReactContextBaseJavaModule {
                     // 如果当前时间已经超过 设定时间,则设置为明天
                     if (calendar.getTimeInMillis() <= System.currentTimeMillis()) {
                         calendar.add(Calendar.DAY_OF_YEAR, 1);
-//                        alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
-//                                AlarmManager.INTERVAL_DAY, pendingIntent);
-                    }
-                    else {
-//                        Calendar now = Calendar.getInstance();
-//                        int currentHour = now.get(Calendar.HOUR_OF_DAY);
-//                        int currentMinute = now.get(Calendar.MINUTE);
-//                        int currentSecond = now.get(Calendar.SECOND);
-//
-//                        // 计算目标时间的秒数
-//                        int targetSeconds = Integer.parseInt(parts[0]) * 3600 + Integer.parseInt(parts[1]) * 60 + Integer.parseInt(parts[2]);
-//
-//                        // 计算当前时间的秒数
-//                        int currentSeconds = currentHour * 3600 + currentMinute * 60 + currentSecond;
-//
-//                        // 计算距离目标时间的秒数
-//                        int secondsUntilTime = targetSeconds - currentSeconds;
-//
-//                        alarmManager.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime()+secondsUntilTime*1000,pendingIntent);
-//
-//                        calendar.add(Calendar.DAY_OF_YEAR, 1);
-//                        alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
-//                                AlarmManager.INTERVAL_DAY, pendingIntent);
                     }
-                    alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
-                        AlarmManager.INTERVAL_DAY, pendingIntent);
+
+                    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
+                            AlarmManager.INTERVAL_DAY, pendingIntent);
+                    Log.i("set alarm status:",time);
 
                 }
 
@@ -159,53 +187,86 @@ public class HolaModule extends ReactContextBaseJavaModule {
         }
     }
 
-    public static long toNearest1000(long number) {
-        return ((number + 500) / 1000) * 1000;
-    }
-
     @ReactMethod
-    public void rnPageLoaded(){
-        GlobalVariable.rnLoaded = true;
-    }
-
-    @ReactMethod
-    public void addLocalPush2(String title,String content,String time){
+    public void addLocalPush2(String jsonData){
         if (getCurrentActivity()==null){
             return;
         }
-        String[] parts = time.split(":");
+        try {
+            JSONArray jsonArray = new JSONArray(jsonData);
+            for (int i = 0; i < jsonArray.length(); i++) {
+                JSONObject jsonObject = jsonArray.getJSONObject(i);
+                String mode = jsonObject.getString("mode");
+                String title = jsonObject.getString("title");
+                String body = jsonObject.getString("body");
+                String strId = jsonObject.getString("id");
+                String categoryId = jsonObject.getString("category_id");
 
-        createNotificationChannel(getCurrentActivity(),"111");
-        Intent intent = new Intent(getCurrentActivity(), AlarmReceiver.class);
-        intent.putExtra("title", title);
-        intent.putExtra("message", content);
-        intent.putExtra("channel", CHANNEL_ID);
+                createNotificationChannel(getCurrentActivity(),categoryId);
+                Intent intent = new Intent(getCurrentActivity(), AlarmReceiver.class);
+                intent.putExtra("title", title);
+                intent.putExtra("message", body);
+                intent.putExtra("channel", categoryId);
+                intent.putExtra("id",strId);
+                intent.putExtra("categoryId",categoryId);
+                intent.putExtra("msg_id",i);
+                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+
+                PendingIntent pendingIntent = PendingIntent.getBroadcast(
+                        getCurrentActivity(), i, intent, android.app.PendingIntent.FLAG_UPDATE_CURRENT);
+
+                AlarmManager alarmManager = (AlarmManager) getCurrentActivity().getSystemService(Context.ALARM_SERVICE);
+
+                AlarmManager.AlarmClockInfo info = alarmManager.getNextAlarmClock();
+                long t = info.getTriggerTime();
+                PendingIntent pt = info.getShowIntent();
+                String aa = info.toString();
+
+                if (mode.equals("ONCE")){
+                    long leftMillis = toNearest1000(jsonObject.getLong("once")-System.currentTimeMillis());
+                    if (leftMillis>0){
+                        alarmManager.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime()+leftMillis,pendingIntent);
+                    }
+                }
+                else {
+                    JSONObject recurring = jsonObject.getJSONObject("recurring");
+                    String time = recurring.getString("time");
+                    String[] parts = time.split(":");
+                    Calendar calendar = Calendar.getInstance();
+                    calendar.setTimeInMillis(System.currentTimeMillis());
+                    calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(parts[0]));
+                    calendar.set(Calendar.MINUTE, Integer.parseInt(parts[1]));
+                    calendar.set(Calendar.SECOND,Integer.parseInt(parts[2]));
 
-        PendingIntent pendingIntent = PendingIntent.getBroadcast(
-                getCurrentActivity(), 0, intent, android.app.PendingIntent.FLAG_IMMUTABLE);
+                    // 如果当前时间已经超过 设定时间,则设置为明天
+                    if (calendar.getTimeInMillis() <= System.currentTimeMillis()) {
+                        calendar.add(Calendar.DAY_OF_YEAR, 1);
+                    }
 
+                    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
+                        AlarmManager.INTERVAL_DAY, pendingIntent);
+                    Log.i("set alarm status:",time);
 
-        Calendar calendar = Calendar.getInstance();
-        calendar.setTimeInMillis(System.currentTimeMillis());
-        calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(parts[0]));
-        calendar.set(Calendar.MINUTE, Integer.parseInt(parts[1]));
-        calendar.set(Calendar.SECOND,Integer.parseInt(parts[2]));
+                }
 
-        // 如果当前时间已经超过 设定时间,则设置为明天
-        if (calendar.getTimeInMillis() <= System.currentTimeMillis()) {
-            calendar.add(Calendar.DAY_OF_YEAR, 1);
+            }
+        } catch (JSONException e) {
+            e.printStackTrace();
         }
+    }
 
-        // 4. 使用 AlarmManager 调度通知
-        AlarmManager alarmManager = (AlarmManager) getCurrentActivity().getSystemService(Context.ALARM_SERVICE);
-        alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime()+10*1000,pendingIntent);
-//        alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
-//                AlarmManager.INTERVAL_DAY, pendingIntent);
+    public static long toNearest1000(long number) {
+        return ((number + 500) / 1000) * 1000;
+    }
+
+    @ReactMethod
+    public void rnPageLoaded(){
+        GlobalVariable.rnLoaded = true;
     }
 
     private void createNotificationChannel(Context context,String channelId) {
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
-            NotificationChannel channel = new NotificationChannel(channelId, CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);
+            NotificationChannel channel = new NotificationChannel(channelId, channelId, NotificationManager.IMPORTANCE_HIGH);
             channel.setDescription(CHANNEL_DESCRIPTION);
 
             NotificationManager notificationManager = context.getSystemService(NotificationManager.class);

+ 225 - 1
android/app/src/main/java/com/hola/MainActivity.java

@@ -1,17 +1,25 @@
 package com.hola;
+
 import android.app.AlarmManager;
 import android.app.NotificationChannel;
 import android.app.NotificationManager;
 import android.app.PendingIntent;
 import android.content.Context;
 import android.content.Intent;
+import android.content.pm.PackageManager;
 import android.graphics.Color;
+import android.location.Location;
+import android.location.LocationListener;
+import android.location.LocationManager;
 import android.os.Build;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.SystemClock;
 import android.util.Log;
+import android.widget.Toast;
 
+import androidx.annotation.NonNull;
+import androidx.core.app.ActivityCompat;
 import androidx.core.app.NotificationCompat;
 
 import expo.modules.ReactActivityDelegateWrapper;
@@ -22,14 +30,24 @@ import com.facebook.react.ReactRootView;
 import com.facebook.react.bridge.Arguments;
 import com.facebook.react.bridge.WritableMap;
 import com.facebook.react.modules.core.DeviceEventManagerModule;
+import com.google.android.gms.location.FusedLocationProviderClient;
+import com.google.android.gms.location.LocationServices;
+import com.google.android.gms.tasks.OnFailureListener;
+import com.google.android.gms.tasks.OnSuccessListener;
 
 import java.util.Calendar;
+import java.util.List;
 
 public class MainActivity extends ReactActivity {
 
   private Handler handler;
   private Runnable runnable;
 
+  private String provider;
+
+  private Location gpsLocation;
+  private Location networkLocation;
+
   private static final String CHANNEL_ID = "local_notification_channel";
   private static final String CHANNEL_NAME = "Daily Reminder";
   private static final String CHANNEL_DESCRIPTION = "Daily reminder notification at 9:00 AM";
@@ -51,13 +69,219 @@ public class MainActivity extends ReactActivity {
    */
 
   @Override
-  protected void onCreate(Bundle savedInstanceState){
+  protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(null);
     checkNotification(getIntent());
+    demo2();
+//    demo();
+//    getLastKnownLocation();
 //    String action = getIntent().getAction();
 //    System.out.println("notification receive action action:"+action);
   }
 
+  private void demo2() {
+    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;
+    }
+    //step1
+    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
+    //step2
+    boolean hasGPS = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
+    boolean hasNetwork = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
+    //step3
+
+    if (hasGPS) {
+      locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 0f,
+              gpsListener);
+    }
+
+    if (hasNetwork){
+      locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000, 0f,
+              networkListener);
+    }
+
+//    if (gpsLocation!=null && networkLocation!=null){
+//      //do something
+//      if (gpsLocation.getAccuracy()>networkLocation.getAccuracy()){
+//
+//      }
+//    }
+  }
+
+  LocationListener gpsListener = new LocationListener() {
+
+    @Override
+    public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
+      // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void onProviderEnabled(String arg0) {
+      // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void onProviderDisabled(String arg0) {
+      // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void onLocationChanged(Location arg0) {
+      // TODO Auto-generated method stub
+      // 更新当前经纬度
+      gpsLocation = arg0;
+    }
+  };
+
+  LocationListener networkListener = new LocationListener() {
+
+    @Override
+    public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
+      // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void onProviderEnabled(String arg0) {
+      // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void onProviderDisabled(String arg0) {
+      // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void onLocationChanged(Location arg0) {
+      // TODO Auto-generated method stub
+      // 更新当前经纬度
+      networkLocation = arg0;
+    }
+  };
+
+  private void getLastKnownLocation() {
+    FusedLocationProviderClient mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
+    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;
+    }
+    mFusedLocationClient.getLastLocation()
+            .addOnSuccessListener(new OnSuccessListener<Location>() {
+              @Override
+              public void onSuccess(Location location) {
+                // GPS location can be null if GPS is switched off
+                if (location != null) {
+//                  getAddress(location);
+                }
+              }
+            })
+            .addOnFailureListener(new OnFailureListener() {
+              @Override
+              public void onFailure(@NonNull Exception e) {
+                Log.d("MapDemoActivity", "Error trying to get last GPS location");
+                e.printStackTrace();
+              }
+            });
+  }
+
+  private void demo() {
+    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;
+    }
+    //获取当前可用的位置控制器
+    List<String> list = locationManager.getProviders(true);
+
+    /*if (list.contains(LocationManager.PASSIVE_PROVIDER)) {
+      //是否为网络位置控制器
+      provider = LocationManager.PASSIVE_PROVIDER;
+    }
+    else if (list.contains(LocationManager.FUSED_PROVIDER)) {
+      //是否为网络位置控制器
+      provider = LocationManager.FUSED_PROVIDER;
+
+    }
+    else */if (list.contains(LocationManager.NETWORK_PROVIDER)) {
+      //是否为网络位置控制器
+      provider = LocationManager.NETWORK_PROVIDER;
+
+    }
+    else if (list.contains(LocationManager.GPS_PROVIDER)) {
+      //是否为GPS位置控制器
+      provider = LocationManager.GPS_PROVIDER;
+    } else {
+      Toast.makeText(this, "请检查网络或GPS是否打开",
+              Toast.LENGTH_LONG).show();
+      return;
+    }
+    boolean isEnabled = false;
+    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
+      isEnabled = locationManager.isLocationEnabled();
+    }
+    Location location = locationManager.getLastKnownLocation(provider);
+    if (location != null) {
+      //获取当前位置,这里只用到了经纬度
+      String string = "纬度为:" + location.getLatitude() + ",经度为:"
+              + location.getLongitude();
+    }
+
+    locationManager.requestLocationUpdates(provider, 2000, 0f,
+            locationListener);
+
+  }
+
+  LocationListener locationListener = new LocationListener() {
+
+    @Override
+    public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
+      // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void onProviderEnabled(String arg0) {
+      // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void onProviderDisabled(String arg0) {
+      // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void onLocationChanged(Location arg0) {
+      // TODO Auto-generated method stub
+      // 更新当前经纬度
+    }
+  };
+
   @Override
   public void onNewIntent(Intent intent) {
     super.onNewIntent(intent);

BIN
android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png


BIN
android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png


BIN
android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png


BIN
android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png


BIN
android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png


+ 1 - 1
android/build.gradle

@@ -5,7 +5,7 @@ buildscript {
         buildToolsVersion = "31.0.0"
         minSdkVersion = 21
         compileSdkVersion = 33
-        targetSdkVersion = 25
+        targetSdkVersion = 26
 //        compileSdkVersion = 33
 //        targetSdkVersion = 33
 

File diff suppressed because it is too large
+ 0 - 0
ios/main.jsbundle


+ 84 - 16
src/features/daynight/DayNightSwiperPopup.tsx

@@ -172,6 +172,39 @@ export default function DayNightSwiperPopup(props: { authInfo: any }) {
         if (e && process.env.TARO_ENV == 'weapp') {
             e.stopPropagation()
         }
+        if (process.env.TARO_ENV == 'weapp') {
+            authLocation()
+        }
+        else {
+            if (kIsIOS) {
+                authLocation()
+            }
+            else {
+                var Jto = require('react-native').NativeModules.HolaModule;
+                Jto.checkSystemLocationService().then(res => {
+                    console.log('授权状态', res)
+                    if (res) {
+                        authLocation()
+                    }
+                    else {
+                        showAlert({
+                            title: t('feature.auth_sys.location_title'),
+                            content: t('feature.auth_sys.location_desc'),
+                            showCancel: true,
+                            cancelText: t('feature.auth_sys.location_cancel'),
+                            confirmText: t('feature.auth_sys.location_confirm'),
+                            confirm: () => {
+                                Jto.openSystemLocationSettings()
+                            }
+                        })
+                    }
+                })
+            }
+        }
+
+    }
+
+    function authLocation() {
         var today = new Date()
         var yesterday = new Date(today.getTime() - 24 * 3600 * 1000)
         var tomorrow = new Date(today.getTime() + 24 * 3600 * 1000 * 5)
@@ -179,7 +212,42 @@ export default function DayNightSwiperPopup(props: { authInfo: any }) {
         var strTomorrow = `${tomorrow.getFullYear()}-${TimeFormatter.padZero(tomorrow.getMonth() + 1)}-${TimeFormatter.padZero(tomorrow.getDate())}`
 
         if (process.env.TARO_ENV == 'rn') {
+            // var Geolocation = require('@react-native-community/geolocation').default
+            // Geolocation.getCurrentPosition(
+            //     ({ coords }) => {
+            //         console.log('location update success',coords)
+            //         const { latitude, longitude, altitude, accuracy, speed } = coords
+            //         const res = {
+            //             latitude,
+            //             longitude,
+            //             speed: speed ?? 0,
+            //             altitude: altitude ?? 0,
+            //             accuracy,
+            //             verticalAccuracy: 0,
+            //             horizontalAccuracy: 0,
+            //             errMsg: 'getLocation:ok'
+            //         }
+
+            //     },
+            //     (err) => {
+            //         console.log('location update failed',err)
+            //         const res = {
+            //             errMsg: 'getLocation fail',
+            //             err
+            //         }
+
+            //     },
+            //     {
+            //         // 当 maximumAge 为 0 时,如果不设置 timeout 或 timeout 太少可能会超时
+            //         timeout: 10000,
+            //         // maximumAge 设置为 0 则会获取当前位置,而不是获取一个前不久缓存的位置
+            //         maximumAge: 100000000,
+            //         enableHighAccuracy: true
+            //     }
+            // );
             Taro.getLocation({
+                highAccuracyExpireTime: 20000,
+                isHighAccuracy:true,
                 success(res) {
                     systemLocation({
                         lat: res.latitude,
@@ -199,25 +267,26 @@ export default function DayNightSwiperPopup(props: { authInfo: any }) {
                             data: JSON.stringify(data as any)
                         })
                         // dispatch(updateMember({ isMember: isMember, gpsInfo: (data as any) }))
-                        if (Taro.getSystemInfoSync().platform == 'android' && process.env.TARO_ENV == 'rn') {
-                            var ToastAndroid = require('react-native').ToastAndroid;
-                            ToastAndroid.show(t('feature.day_night.location_updated'), ToastAndroid.LONG);
-                        }
-                        else {
-                            showAlert({
-                                title: 'Success',
-                                content: t('feature.day_night.location_updated'),
-                                showCancel: false
-                            })
-                            // Taro.showToast({
-                            //     title: t('feature.day_night.location_updated'),
-                            //     icon: 'none'
-                            // })
-                        }
+                        // if (Taro.getSystemInfoSync().platform == 'android' && process.env.TARO_ENV == 'rn') {
+                        //     var ToastAndroid = require('react-native').ToastAndroid;
+                        //     ToastAndroid.show(t('feature.day_night.location_updated'), ToastAndroid.LONG);
+                        // }
+                        // else {
+                        showAlert({
+                            title: 'Success',
+                            content: t('feature.day_night.location_updated'),
+                            showCancel: false
+                        })
+                        // Taro.showToast({
+                        //     title: t('feature.day_night.location_updated'),
+                        //     icon: 'none'
+                        // })
+                        // }
 
                     })
                 },
                 fail(res) {
+                    console.log('location update failed reason', res)
                     if (res.errMsg == 'Permissions denied!') {
                         showAlert({
                             title: t('feature.auth_sys.location_title'),
@@ -304,7 +373,6 @@ export default function DayNightSwiperPopup(props: { authInfo: any }) {
 
             }
         })
-
     }
 
     global.showDayNightSwiperPop = (isNight, strNight, strDay) => {

+ 21 - 21
src/features/trackTimeDuration/actions/TrackTimeActions.tsx

@@ -111,37 +111,37 @@ export const uploadLocalPushInfo = (params) => {
 
 export const getLocalPush = () => {
     if (process.env.TARO_ENV == 'rn') {
-        console.log('leon aaaaa')
         PushNotification.checkPermissions((res) => {
+            console.log('notification status begin')
+            console.log('notification status',res)
             //允许授权
             if ((kIsIOS && res.authorizationStatus == 2) || (!kIsIOS && res.alert)) {
                 request({
                     url: API_LOCAL_PUSHES, method: 'GET', data: {}
                 }).then(res => {
-                    console.log('leon aaaaavvv', res)
                     const { messages } = res as any;
                     if (messages.length == 0) {
                         return;
                     }
-                    PushNotification.configure({
-                        onRegister: function (token) {
-                            console.log('TOKEN:', token);
-                        },
-
-                        onNotification: function (notification) {
-                            console.log('NOTIFICATION:', notification);
-                            // notification.finish(PushNotificationIOS.FetchResult.NoData);
-                        },
-
-                        permissions: {
-                            alert: true,
-                            badge: true,
-                            sound: true,
-                        },
-
-                        popInitialNotification: true,
-                        requestPermissions: true,
-                    });
+                    // PushNotification.configure({
+                    //     onRegister: function (token) {
+                    //         console.log('TOKEN:', token);
+                    //     },
+
+                    //     onNotification: function (notification) {
+                    //         console.log('NOTIFICATION:', notification);
+                    //         // notification.finish(PushNotificationIOS.FetchResult.NoData);
+                    //     },
+
+                    //     permissions: {
+                    //         alert: true,
+                    //         badge: true,
+                    //         sound: true,
+                    //     },
+
+                    //     popInitialNotification: true,
+                    //     // requestPermissions: true,
+                    // });
                     PushNotification.cancelAllLocalNotifications()
 
                     if (kIsIOS) {

+ 16 - 11
src/utils/native_permission_check.tsx

@@ -23,19 +23,24 @@ export const uploadPermissions = () => {
                 else {
                     global.notification = 'denied'
                 }
-
-                clientInfo({
-                    perm: {
-                        android: {
-                            camera: statuses[PERMISSIONS.ANDROID.CAMERA],
-                            location: {
-                                location: statuses[PERMISSIONS.ANDROID.ACCESS_COARSE_LOCATION]
-                            },
-                            notification: global.notification
+                var Jto = require('react-native').NativeModules.HolaModule;
+                Jto.checkSystemLocationService().then(enableLocation=>{
+                    clientInfo({
+                        perm: {
+                            android: {
+                                camera: statuses[PERMISSIONS.ANDROID.CAMERA],
+                                location: {
+                                    location_services_enabled:enableLocation,
+                                    authorization_status: statuses[PERMISSIONS.ANDROID.ACCESS_COARSE_LOCATION]
+                                },
+                                notification: global.notification
+                            }
+    
                         }
-
-                    }
+                    })
                 })
+
+                
             })
         });
         return

Some files were not shown because too many files changed in this diff