| | |
| | | */ |
| | | public class MyLocationService extends Service { |
| | | |
| | | |
| | | private LocationManager locationManager; |
| | | private MyLocationListener listener; |
| | | |
| | |
| | | @Override |
| | | public int onStartCommand(Intent intent, int flags, int startId) { |
| | | MyLog.i("onStartCommand()"); |
| | | isSingle = intent.getBooleanExtra("isSingle", false); |
| | | if (intent != null) { |
| | | isSingle = intent.getBooleanExtra("isSingle", false); |
| | | } |
| | | if (!isSingle) { |
| | | // 在API11之后构建Notification的方式 |
| | | Notification.Builder builder = new Notification.Builder |
| | |
| | | MyLog.i("原生定位没有权限>>>>"); |
| | | return; |
| | | } |
| | | locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER , 1000, 0, listener); |
| | | locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, listener); |
| | | } catch (Exception e) { |
| | | CrashReport.postCatchedException(e); |
| | | } |
| | |
| | | @Override |
| | | public void onDestroy() { |
| | | MyLog.i("MyLocationService--onDestroy"); |
| | | |
| | | // 停止前台服务--参数:表示是否移除之前的通知 |
| | | stopForeground(true); |
| | | // 获取NotificationManager并取消通知,确保通知被移除 |