需要檢測GPS或者WiFi或者手機網絡是否可用,我當前的代碼可以檢測出GPS。但是檢測網絡時就報錯:
The method isProviderEnabled(String) in the type LocationManager is not applicable for the arguments (String, String)
代碼:
if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER)){
Toast.makeText(this, "GPS is Enabled in your device", Toast.LENGTH_SHORT).show();
}else{
displayAlert();
}
你需要分開檢查
if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) ||
locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)){
Toast.makeText(this, "GPS/Network is Enabled in your device",
Toast.LENGTH_SHORT).show();
}else{
displayAlert();
}