我无法确定是GPS打开还是关闭,isProviderEnabled总是"假"但GPS打开.
public abstract class BaseGPSActivity extends AppCompatActivity{
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Log.v(TAG, " GPS is enabled: "+isGPSEnabled()))
Run Code Online (Sandbox Code Playgroud)
public boolean isGPSEnabled(){
String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if(provider != null)
Log.v(TAG, " Location providers: "+provider);
return mLocationManager!=null && mLocationManager.isProviderEnabled( LocationManager.GPS_PROVIDER );
}
Run Code Online (Sandbox Code Playgroud)
输出是:
V/BaseGPSActivity: Location providers: network
V/BaseGPSActivity: GPS is enabled: false
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1237 次 |
| 最近记录: |