From 83c474f4f4b5adbfeec79340ac1ed8e88cfa8316 Mon Sep 17 00:00:00 2001 From: LiuSiXiang-007 <2535147127@qq.com> Date: Wed, 13 Mar 2024 15:45:01 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=20=E5=AE=9A=E6=9C=9F30s=E5=90=8E=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=AE=9A=E4=BD=8D=E9=99=90=E5=88=B6-=E5=BF=85?= =?UTF-8?q?=E9=A1=BB=E5=9C=A8=E9=A1=B6=E7=95=99=E4=B9=8B=E5=90=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 7 +- .../com/kanglai/push/mapper/PushMapper.java | 4 + .../push/service/Impl/PushServiceImpl.java | 5 + .../com/kanglai/push/service/PushService.java | 3 + .../kanglai/push/ui/vm/MessageViewModel.java | 38 ++++ .../com/kanglai/push/util/AlarmReceiver.java | 113 +++++++++++ .../com/kanglai/push/util/HistoryMsgUtil.java | 20 +- .../kanglai/push/util/LocationService.java | 176 +++++++++--------- 8 files changed, 270 insertions(+), 96 deletions(-) create mode 100644 app/src/main/java/com/kanglai/push/util/AlarmReceiver.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 25c763e..d968fda 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -46,6 +46,9 @@ + + + - + + + updatePushType(@Body PushType pushType); + + @GET("system_proxy/system/user/info") + Observable> getUserInfo(); } diff --git a/app/src/main/java/com/kanglai/push/service/Impl/PushServiceImpl.java b/app/src/main/java/com/kanglai/push/service/Impl/PushServiceImpl.java index e16367e..d8bf3c1 100644 --- a/app/src/main/java/com/kanglai/push/service/Impl/PushServiceImpl.java +++ b/app/src/main/java/com/kanglai/push/service/Impl/PushServiceImpl.java @@ -71,4 +71,9 @@ public class PushServiceImpl implements PushService { public Observable updatePushType(PushType pushType) { return pushMapper.updatePushType(pushType); } + + @Override + public Observable> getUserInfo() { + return pushMapper.getUserInfo(); + } } diff --git a/app/src/main/java/com/kanglai/push/service/PushService.java b/app/src/main/java/com/kanglai/push/service/PushService.java index 48c67a6..f140703 100644 --- a/app/src/main/java/com/kanglai/push/service/PushService.java +++ b/app/src/main/java/com/kanglai/push/service/PushService.java @@ -42,4 +42,7 @@ public interface PushService { /** 更新推送类型*/ Observable updatePushType(PushType pushType); + + /** 获取用户信息 */ + Observable> getUserInfo(); } diff --git a/app/src/main/java/com/kanglai/push/ui/vm/MessageViewModel.java b/app/src/main/java/com/kanglai/push/ui/vm/MessageViewModel.java index ac3b1eb..e9d7976 100644 --- a/app/src/main/java/com/kanglai/push/ui/vm/MessageViewModel.java +++ b/app/src/main/java/com/kanglai/push/ui/vm/MessageViewModel.java @@ -6,16 +6,22 @@ import androidx.annotation.NonNull; import androidx.lifecycle.LifecycleOwner; import com.blankj.utilcode.util.ArrayUtils; +import com.blankj.utilcode.util.CacheDiskUtils; +import com.blankj.utilcode.util.LogUtils; import com.blankj.utilcode.util.Utils; +import com.dolphin.core.http.HttpRequest; import com.dolphin.core.http.api.ResultResponse; import com.dolphin.core.http.exception.ExceptionHandle; +import com.dolphin.core.util.PermissionUtil; import com.dolphin.core.util.RxUtil; import com.dolphin.core.util.ToastUtil; import com.kanglai.push.app.AppApplication; +import com.kanglai.push.constant.CacheConstant; import com.kanglai.push.di.component.DaggerServiceComponent; import com.kanglai.push.entity.LocalPushChatMsg; import com.kanglai.push.entity.ResultVo; import com.kanglai.push.entity.SystemUser; +import com.kanglai.push.entity.User; import com.kanglai.push.service.PushService; import com.kanglai.push.ui.fragment.MessageFragment; import com.kanglai.push.util.HistoryMsgUtil; @@ -58,6 +64,10 @@ public class MessageViewModel extends ToolbarViewModel { /** 核心 - 刷新数据 */ public void refresh(RefreshLayout refresh) { + if (HistoryMsgUtil.noneId()) { + getUserInfo(refresh); + return; + } Map localHistoryMsg = HistoryMsgUtil.select(); if (localHistoryMsg != null && !localHistoryMsg.isEmpty()) { mActivity.mAdapter.refresh(localHistoryMsg.values()); @@ -66,6 +76,34 @@ public class MessageViewModel extends ToolbarViewModel { refresh.finishRefresh(); } + /** 加载一次个人信息后 重新加载界面 */ + private void getUserInfo(RefreshLayout refresh) { + pushService.getUserInfo() + .compose(RxUtil.schedulersTransformer()) + .compose(RxUtil.exceptionTransformer()) + .doOnSubscribe(this) + .subscribe(new DisposableObserver>() { + @Override + public void onNext(ResultResponse R) { + CacheDiskUtils.getInstance().put(CacheConstant.USER_INFO, R.getData()); + } + + @Override + public void onError(Throwable e) { + ToastUtil.showBottomWarn("用户信息加载失败,请重新登录"); + ExceptionHandle.baseExceptionMsg(e); + HttpRequest.getInstance().retrofit.create(ExceptionHandle.LoginMapper.class) + .logout().compose(RxUtil.schedulersTransformer()); + PermissionUtil.logout(); + } + + @Override + public void onComplete() { + refresh(refresh); + } + }); + } + /** 加载新的缓存消息记录 */ public void addLocalHistoryMsg(String userId, String content) { pushService.getUserById(userId) diff --git a/app/src/main/java/com/kanglai/push/util/AlarmReceiver.java b/app/src/main/java/com/kanglai/push/util/AlarmReceiver.java new file mode 100644 index 0000000..078e1e7 --- /dev/null +++ b/app/src/main/java/com/kanglai/push/util/AlarmReceiver.java @@ -0,0 +1,113 @@ +package com.kanglai.push.util; + +import static android.content.Context.ALARM_SERVICE; + +import android.app.AlarmManager; +import android.app.PendingIntent; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.os.SystemClock; + +import com.amap.api.location.AMapLocation; +import com.amap.api.location.AMapLocationClient; +import com.amap.api.location.AMapLocationClientOption; +import com.amap.api.location.AMapLocationListener; +import com.blankj.utilcode.util.LogUtils; + +/** + * 报警广播 + * + *在一定时间之后 获取/上传一次定位数据 + * @Author: liusixiang007 + * @since: 2024/3/8 + */ +public class AlarmReceiver extends BroadcastReceiver implements AMapLocationListener { + + private AMapLocationClient aMapLocationClient = null; + + /** 在特定时间点或经过一定时间后执行某个操作 */ + private AlarmManager mAlarmManager = null; + + /** 用于表示即将发生的操作的意图 */ + private PendingIntent pendingIntent; + + /** 每次定位间隔时间 */ + private int TIME_INTERVAL = 30 * 1000; + + @Override + public void onReceive(Context context, Intent intent) { + + if (intent.getAction().equals("com.kanglai.push.util.AlarmReceiver")) { // 判断从哪里打开的广播 + if (HistoryMsgUtil.noneId()) context.startService(new Intent(context, LocationService.class)); + return; + } + + mAlarmManager = (AlarmManager) context.getSystemService(ALARM_SERVICE); // 获取系统级别的 AlarmManager 服务实例 + Intent alarmIntent = new Intent(context, AlarmReceiver.class); + alarmIntent.setAction("youxing_warn"); + /** 且如果已经存在相同 Intent 的 PendingIntent,则更新当前的 PendingIntent */ + pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); + + // 这里需要设置一个类似于闹钟的配置 间隔一定时间之后 唤醒 + // Android系统 大于等于6时 - setExactAndAllowWhileIdle 设置精确的闹钟,即使应用处于低功耗模式(Doze 模式)或应用处于后台并且在 Idle 状态下也可以触发 + mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + TIME_INTERVAL, pendingIntent); + // Android 大于等于4 - setExact 设置精确的闹钟,即在指定的时间精确唤醒设备执行任务 + // mAlarmManager.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + TIME_INTERVAL, pendingIntent); + + LogUtils.i("--------------------------------AlarmReceiver---------------------------------------"); + /** 上传之前需要判断一次用户登录状态 即 id 时候存在 */ + locationConfigure(HistoryMsgUtil.noneId(),context); + } + + /** 获取定位数据 */ + private void locationConfigure(boolean start, Context context) { + if (start) { // 开始定位 + try { + aMapLocationClient = new AMapLocationClient(context); + } catch (Exception e) { + throw new RuntimeException(e); + } + /** 这里要实现AMapLocationListener接口,AMapLocationListener接口只有onLocationChanged方法可以实现,用于接收异步返回的定位结果,参数是AMapLocation类型。 */ + aMapLocationClient.setLocationListener(this); // 设置定位回调监听 + AMapLocationClientOption aMapLocationClientOption = new AMapLocationClientOption(); + /** Hight_Accuracy高精度模式,Battery_Saving为低功耗模式,Device_Sensors是仅设备模式 */ +// aMapLocationClientOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy); +// aMapLocationClientOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Battery_Saving); + aMapLocationClientOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Device_Sensors); + aMapLocationClientOption.setNeedAddress(true); // 是否返回位置信息 + aMapLocationClientOption.setOnceLocation(true); // 是否只定位一次(默认为false) + aMapLocationClientOption.setWifiScan(true); // 允许调用WIFI刷新-默认true + // aMapLocationClientOption.setMockEnable(false); // 是否允许虚拟定位 + aMapLocationClientOption.setHttpTimeOut(1000 * 20); // http超时时间 20s + aMapLocationClientOption.setInterval(1000 * 5); // 返回定位间隔时间 3s返回一次 + aMapLocationClientOption.setLocationCacheEnable(false); // 缓存机制 + + aMapLocationClient.setLocationOption(aMapLocationClientOption); + aMapLocationClient.startLocation(); // 开始定位 + }else { // 结束定位 关闭定位服务 + if (aMapLocationClient != null) aMapLocationClient.onDestroy(); + LogUtils.d("-----------定位服务未开始"); + } + } + + @Override + public void onLocationChanged(AMapLocation aMapLocation) { + if (aMapLocation != null) { + if (aMapLocation.getErrorCode() == 0) { +// LogUtils.d( +// "设备定位成功,设备所在位置:"+ +// aMapLocation.getCountry() // 国家信息 +// + aMapLocation.getProvince() // 省份信息 +// + aMapLocation.getCity() // 城市信息 +// + aMapLocation.getDistrict() // 区信息 +// + aMapLocation.getStreet() // 街道信息 +// + aMapLocation.getStreetNum() // 门牌号信息 +// + "当前时间" +// + TimeFormatUtil.getCurrentTime() +// ); + LogUtils.d("------纬度:" + aMapLocation.getLatitude() + "-----经度" + aMapLocation.getLongitude() + "-----" + TimeFormatUtil.getCurrentTime()); + }else LogUtils.e("设备定位失败 - 错误信息>>>>>>>>>>>>>" + aMapLocation.getErrorCode() + ",错误信息: " + aMapLocation.getErrorInfo()); + } + } +} diff --git a/app/src/main/java/com/kanglai/push/util/HistoryMsgUtil.java b/app/src/main/java/com/kanglai/push/util/HistoryMsgUtil.java index 6d3a983..0f145f5 100644 --- a/app/src/main/java/com/kanglai/push/util/HistoryMsgUtil.java +++ b/app/src/main/java/com/kanglai/push/util/HistoryMsgUtil.java @@ -40,15 +40,21 @@ public class HistoryMsgUtil { user = CacheDiskUtils.getInstance().getParcelable(CacheConstant.USER_INFO, User.CREATOR, new User()); } + /** 检查id是否消失 */ + public Boolean noneId(){ + if (StringUtils.isEmpty(user.getId())) return true; + else return false; + } + /** 获取缓存的列表数据 */ public HashMap select() { - if (StringUtils.isEmpty(user.getId())) { // 用户信息过期就需要重新登录 - HttpRequest.getInstance().retrofit.create(ExceptionHandle.LoginMapper.class) - .logout().compose(RxUtil.schedulersTransformer()); - PermissionUtil.logout(); - ToastUtil.show("登录状态已过期,请重新登录"); - return null; - } +// if (StringUtils.isEmpty(user.getId())) { +// HttpRequest.getInstance().retrofit.create(ExceptionHandle.LoginMapper.class) +// .logout().compose(RxUtil.schedulersTransformer()); +// PermissionUtil.logout(); +// ToastUtil.show("登录状态已过期,请重新登录"); +// return null; +// } String localHistoryMsgJson = CacheDiskUtils.getInstance().getString(user.getId().concat(user.getUserType()) ,""); Type type = new TypeToken>(){}.getType(); return new Gson().fromJson(localHistoryMsgJson, type); diff --git a/app/src/main/java/com/kanglai/push/util/LocationService.java b/app/src/main/java/com/kanglai/push/util/LocationService.java index 0fd9cbc..5c7d4b2 100644 --- a/app/src/main/java/com/kanglai/push/util/LocationService.java +++ b/app/src/main/java/com/kanglai/push/util/LocationService.java @@ -1,36 +1,37 @@ package com.kanglai.push.util; +import android.app.AlarmManager; import android.app.Notification; +import android.app.NotificationChannel; +import android.app.NotificationManager; +import android.app.PendingIntent; import android.app.Service; import android.content.Intent; import android.graphics.BitmapFactory; -import android.os.Build; +import android.graphics.Color; import android.os.IBinder; +import android.os.SystemClock; import androidx.annotation.Nullable; -import androidx.annotation.RequiresApi; import androidx.core.app.NotificationCompat; -import com.amap.api.location.AMapLocation; -import com.amap.api.location.AMapLocationClient; -import com.amap.api.location.AMapLocationClientOption; -import com.amap.api.location.AMapLocationListener; import com.blankj.utilcode.util.LogUtils; -import com.dolphin.core.util.NotificationUtil; import com.kanglai.push.R; -import com.kanglai.push.util.TimeFormatUtil; -import com.taobao.accs.common.Constants; +import com.kanglai.push.ui.activity.TabBarActivity; -import java.util.Random; /** - * 高德长时间定位 + * 拉起任务栏提示 以及 后台定位广播 * @Author: liusixiang007 * @since: 2024/2/28 */ -public class LocationService extends Service implements AMapLocationListener { +public class LocationService extends Service{ - private AMapLocationClient aMapLocationClient = null; + /** 在特定时间点或经过一定时间后执行某个操作 */ + private AlarmManager mAlarmManager = null; + + /** 用于表示即将发生的操作的意图 */ + private PendingIntent pendingIntent; @Nullable @Override @@ -41,35 +42,60 @@ public class LocationService extends Service implements AMapLocationListener { @Override public void onCreate() { super.onCreate(); - } - - - /** - * 返回位置信息 - * @param aMapLocation 返回具体的位置信息对象 - */ - @Override - public void onLocationChanged(AMapLocation aMapLocation) { - if (aMapLocation != null) { - if (aMapLocation.getErrorCode() == 0) { - LogUtils.d( - "设备定位成功,设备所在位置:"+ - aMapLocation.getCountry() // 国家信息 - + aMapLocation.getProvince() // 省份信息 - + aMapLocation.getCity() // 城市信息 - + aMapLocation.getDistrict() // 区信息 - + aMapLocation.getStreet() // 街道信息 - + aMapLocation.getStreetNum() // 门牌号信息 - + "当前时间" - + TimeFormatUtil.getCurrentTime() - ); - - LogUtils.d("----------------------------------纬度:" - + aMapLocation.getLatitude() - + "经度" - + aMapLocation.getLongitude()); - }else LogUtils.e("设备定位失败 - 错误信息>>>>>>>>>>>>>" + aMapLocation.getErrorCode() + ",错误信息: " + aMapLocation.getErrorInfo()); - } + NotificationChannel notificationChannel = null; + Notification.Builder builder; + NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); + +// 原本是需要判断安装Android的版本号 当前app最低安装版本 就是Android 10 +// if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { + notificationChannel = new NotificationChannel("CHANNEL_ONE_ID", + "CHANNEL_ONE_ID", NotificationManager.IMPORTANCE_HIGH); + notificationChannel.enableLights(true); + notificationChannel.setLightColor(Color.RED); + notificationChannel.setShowBadge(true); + notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC); + manager.createNotificationChannel(notificationChannel); + builder = new Notification.Builder(this, "CHANNEL_ONE_ID"); +// } + /** 设置任务栏提示 */ +// NotificationCompat.Builder builder = new NotificationCompat.Builder(this); +// Notification notification = new Notification.Builder(this).setChannelId("CHANNEL_ONE_ID") +// .setTicker("Nature") +// .setSmallIcon(R.drawable.umeng_push_notification_default_small_icon) +// .setContentTitle(getString(R.string.app_name)) +// .setContentText("后台运行中") +// .build(); +// notification.flags |= Notification.FLAG_NO_CLEAR; +// startForeground(1, notification); + builder.setTicker("友信第一次"); + builder.setSmallIcon(R.drawable.umeng_push_notification_default_small_icon); // 设置最小图标 + builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.icon_app)); // 设置大图标 + builder.setPriority(Notification.PRIORITY_MAX); // 设置优先级 优先级低则会被隐藏 + //设置通知时间,默认为系统发出通知的时间,通常不用设置 + //builder.setWhen(System.currentTimeMillis()); + builder.setOnlyAlertOnce(true); // 状态栏是否能被清除 + builder.setContentTitle(getString(R.string.app_name)); // 任务栏标题 + builder.setContentText("后台定位运行中..."); // 友信正在为您安全守护中... + builder.setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this, TabBarActivity.class),0 )); // 任务栏运行意图 点击跳转 + //设置消息的提醒方式,震动提醒:DEFAULT_VIBRATE 声音提醒:NotificationCompat.DEFAULT_SOUND + //三色灯提醒NotificationCompat.DEFAULT_LIGHTS 以上三种方式一起:DEFAULT_ALL + //.setLights(Color.YELLOW, 300, 0)//单独设置呼吸灯,一般三种颜色:红,绿,蓝,经测试,小米支持黄色 + //.setSound(url)//单独设置声音 + //.setVibrate(new long[] { 100, 250, 100, 250, 100, 250 })//单独设置震动 + builder.setDefaults(NotificationCompat.DEFAULT_ALL); // 通知默认行为 震动、声音 等等 + LogUtils.d("LocationService-----onCreate"); + /** + * android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP + * 安卓版本大于5.0时 Notification 的显示等级 + * + * VISIBILITY_PUBLIC只有在没有锁屏时会显示通知 + * VISIBILITY_PRIVATE任何情况都会显示通知 + * VISIBILITY_SECRET在安全锁和没有锁屏的情况下显示通知 + * + * */ + builder.setVisibility(Notification.VISIBILITY_PRIVATE); + startForeground(1, builder.build()); // 开始运行 + mAlarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); // 设置唤醒周期 } /** @@ -81,58 +107,32 @@ public class LocationService extends Service implements AMapLocationListener { */ @Override public int onStartCommand(Intent intent, int flags, int startId) { - locationConfigure(true); - // 将service设置为前台service 以达成保活 - -// NotificationUtil.notify(new Random().nextInt(), builder -> builder -// .setContentText("友信正在为您安全守护中...") -// .setContentTitle(" ") -// .setCategory(Notification.CATEGORY_REMINDER) -// .setStyle(new Notification.BigTextStyle().bigText("人生得意须尽欢,莫使金樽空对月。\n 天生我材必有用,千金散尽还复来。")) -// .setStyle(new Notification.BigPictureStyle() -// .bigPicture(BitmapFactory.decodeResource(getResources(), R.drawable.icon_app))) -// .setUsesChronometer(true).setNumber(10) ); - + int anhour = 10 * 1000; + /** SystemClock.elapsedRealtime() -获取系统自设备启动以来的时间 */ + long triggerAtMillis = SystemClock.elapsedRealtime() + anhour; + Intent alarmIntent = new Intent(LocationService.this, AlarmReceiver.class); + alarmIntent.setAction("youxing_location"); + /** PendingIntent.getBroadcast 广播这个意图 且如果已经存在相同 Intent 的 PendingIntent,则更新当前的 PendingIntent */ + pendingIntent = PendingIntent.getBroadcast(LocationService.this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); + mAlarmManager.cancel(pendingIntent); + // 系统版本大于等于8时 + mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAtMillis, pendingIntent); + // Build.VERSION_CODES.M + // 当系统版本小于6 - mAlarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAtMillis, TIME_INTERVAL, pendingIntent); + // 当系统版本小于4 - mAlarmManager.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAtMillis, pendingIntent); + flags = Service.START_FLAG_REDELIVERY; +// LogUtils.d("LocationService-----onStartCommand"); return super.onStartCommand(intent, flags, startId); } @Override public void onDestroy() { - locationConfigure(false); +// locationConfigure(false); +// LogUtils.d("LocationService-----onCreate"); + // 指定广播路径 + Intent intent = new Intent("com.kanglai.push.util.AlarmReceiver"); + sendBroadcast(intent); super.onDestroy(); } - /** - * 配置定位服务参数 - * @param start 定位状态 - */ - private void locationConfigure(boolean start) { - if (start) { // 开始定位 - try { - aMapLocationClient = new AMapLocationClient(getApplicationContext()); - } catch (Exception e) { - throw new RuntimeException(e); - } - /** 这里要实现AMapLocationListener接口,AMapLocationListener接口只有onLocationChanged方法可以实现,用于接收异步返回的定位结果,参数是AMapLocation类型。 */ - aMapLocationClient.setLocationListener(this); // 设置定位回调监听 - AMapLocationClientOption aMapLocationClientOption = new AMapLocationClientOption(); - /** Hight_Accuracy高精度模式,Battery_Saving为低功耗模式,Device_Sensors是仅设备模式 */ -// aMapLocationClientOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy); -// aMapLocationClientOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Battery_Saving); - aMapLocationClientOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Device_Sensors); - aMapLocationClientOption.setNeedAddress(true); // 是否返回位置信息 - aMapLocationClientOption.setOnceLocation(false); // 是否只定位一次(默认为false) - aMapLocationClientOption.setWifiScan(true); // 允许调用WIFI刷新-默认true - // aMapLocationClientOption.setMockEnable(false); // 是否允许虚拟定位 - aMapLocationClientOption.setHttpTimeOut(1000 * 20); // http超时时间 20s - aMapLocationClientOption.setInterval(1000 * 5); // 返回定位间隔时间 3s返回一次 - aMapLocationClientOption.setLocationCacheEnable(false); // 缓存机制 - - aMapLocationClient.setLocationOption(aMapLocationClientOption); - aMapLocationClient.startLocation(); // 开始定位 - }else { // 结束定位 关闭定位服务 - if (aMapLocationClient != null) aMapLocationClient.onDestroy(); - LogUtils.d("aMapLocation ----------- 定位服务已关闭"); - } - } }