1
1
package com .blankj .subutil .util ;
2
2
3
+ import android .Manifest ;
3
4
import android .annotation .SuppressLint ;
5
+ import android .content .Context ;
4
6
import android .content .Intent ;
5
7
import android .location .Address ;
6
8
import android .location .Criteria ;
11
13
import android .location .LocationProvider ;
12
14
import android .os .Bundle ;
13
15
import android .provider .Settings ;
16
+ import android .support .annotation .RequiresPermission ;
14
17
import android .util .Log ;
15
18
16
19
import java .io .IOException ;
17
20
import java .util .List ;
18
21
import java .util .Locale ;
19
22
20
- import static android .content .Context .LOCATION_SERVICE ;
21
-
22
23
/**
23
24
* <pre>
24
25
* author: Blankj
@@ -111,7 +112,7 @@ private LocationUtils() {
111
112
* @return {@code true}: 是<br>{@code false}: 否
112
113
*/
113
114
public static boolean isGpsEnabled () {
114
- LocationManager lm = (LocationManager ) Utils .getApp ().getSystemService (LOCATION_SERVICE );
115
+ LocationManager lm = (LocationManager ) Utils .getApp ().getSystemService (Context . LOCATION_SERVICE );
115
116
return lm != null && lm .isProviderEnabled (LocationManager .GPS_PROVIDER );
116
117
}
117
118
@@ -121,7 +122,7 @@ public static boolean isGpsEnabled() {
121
122
* @return {@code true}: 是<br>{@code false}: 否
122
123
*/
123
124
public static boolean isLocationEnabled () {
124
- LocationManager lm = (LocationManager ) Utils .getApp ().getSystemService (LOCATION_SERVICE );
125
+ LocationManager lm = (LocationManager ) Utils .getApp ().getSystemService (Context . LOCATION_SERVICE );
125
126
return lm != null
126
127
&& (lm .isProviderEnabled (LocationManager .NETWORK_PROVIDER )
127
128
|| lm .isProviderEnabled (LocationManager .GPS_PROVIDER )
@@ -151,10 +152,10 @@ public static void openGpsSettings() {
151
152
* @param listener 位置刷新的回调接口
152
153
* @return {@code true}: 初始化成功<br>{@code false}: 初始化失败
153
154
*/
154
- @ SuppressLint ( "MissingPermission" )
155
+ @ RequiresPermission ( Manifest . permission . ACCESS_FINE_LOCATION )
155
156
public static boolean register (long minTime , long minDistance , OnLocationChangeListener listener ) {
156
157
if (listener == null ) return false ;
157
- mLocationManager = (LocationManager ) Utils .getApp ().getSystemService (LOCATION_SERVICE );
158
+ mLocationManager = (LocationManager ) Utils .getApp ().getSystemService (Context . LOCATION_SERVICE );
158
159
if (mLocationManager == null
159
160
|| (!mLocationManager .isProviderEnabled (LocationManager .NETWORK_PROVIDER )
160
161
&& !mLocationManager .isProviderEnabled (LocationManager .GPS_PROVIDER ))) {
0 commit comments