检测GPS或者网络是否可用

需要检测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();
    }

这个isProviderEnabled只有一个参数
你传递的是两个参数