当前位置: 首页>>代码示例>>Java>>正文


Java LocationManager.isProviderEnabled方法代码示例

本文整理汇总了Java中android.location.LocationManager.isProviderEnabled方法的典型用法代码示例。如果您正苦于以下问题:Java LocationManager.isProviderEnabled方法的具体用法?Java LocationManager.isProviderEnabled怎么用?Java LocationManager.isProviderEnabled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.location.LocationManager的用法示例。


在下文中一共展示了LocationManager.isProviderEnabled方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getLocation

import android.location.LocationManager; //导入方法依赖的package包/类
public Location getLocation() {

        if (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            Toast.makeText(context, "Permission not granted", Toast.LENGTH_SHORT).show();
            return null;
        }
        LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
        boolean isGPSEnabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
        if (isGPSEnabled) {
            lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 6000, 10, this);
            Location l = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
            return l;
        } else {
            Toast.makeText(context, "Please enable GPS !", Toast.LENGTH_LONG).show();
        }
        return null;
    }
 
开发者ID:StickyBoi,项目名称:SkateSpot,代码行数:18,代码来源:GPSTracker.java

示例2: onRequestPermissionsResult

import android.location.LocationManager; //导入方法依赖的package包/类
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
	if (requestCode == REQUEST_LOCATION) {
		if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
			final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
			if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
				GPSrequest();
			} else {
				gmaps.setMyLocationEnabled(true);
				gmaps.getMyLocation();
			}
		} else {
			Toast.makeText(this, "Akses lokasi tidak di izinkan", 6000).show();
			finish();
		}
	}
}
 
开发者ID:agusibrahim,项目名称:go-jay,代码行数:18,代码来源:MainActivity.java

示例3: init

import android.location.LocationManager; //导入方法依赖的package包/类
@Override
public ControllerParent<GpsShield> init(String tag) {
    mLocationClient = new GoogleApiClient.Builder(getApplication())
            .addApi(LocationServices.API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();
    mUpdatesRequested = false;
    manager = (LocationManager) getApplication().getSystemService(
            Context.LOCATION_SERVICE);
    // check if Google play services available, no dialog displayed
    if (isGoogleplayServicesAvailableNoDialogs()) {
        if (manager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
            startGps();
    }
    return super.init(tag);
}
 
开发者ID:Dnet3,项目名称:CustomAndroidOneSheeld,代码行数:18,代码来源:GpsShield.java

示例4: check

import android.location.LocationManager; //导入方法依赖的package包/类
private void check(CallbackContext callbackContext){
Context context = this.cordova.getActivity().getApplicationContext();
  final LocationManager manager = (LocationManager) context.getSystemService( Context.LOCATION_SERVICE );
  if ( manager.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) {
	callbackContext.success();
  }else{
	callbackContext.error(0);
}
}
 
开发者ID:disit,项目名称:siiMobilityAppKit,代码行数:10,代码来源:CheckGPS.java

示例5: checkGPSStatus

import android.location.LocationManager; //导入方法依赖的package包/类
private boolean checkGPSStatus(final Activity activity, final int code) {
    final LocationManager locationManager = (LocationManager) activity.getSystemService(Context.LOCATION_SERVICE);
    if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
    /*&& !locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)*/) {
        final Dialog dialog = buildAlertMessageNoGps(activity, code);
        dialog.show();
        return true;
    }
    return false;
}
 
开发者ID:WorldBank-Transport,项目名称:RoadLab-Pro,代码行数:11,代码来源:GpsManager.java

示例6: checkLocationServicesStatus

import android.location.LocationManager; //导入方法依赖的package包/类
/**
 * Check if location services are enabled in the device
 */
void checkLocationServicesStatus() {
    final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        buildAlertMessageNoGps();
    } else {
        getDeviceLocation();
    }
}
 
开发者ID:CityZenApp,项目名称:Android-Development,代码行数:12,代码来源:MainActivity.java

示例7: getValidProvider

import android.location.LocationManager; //导入方法依赖的package包/类
@Nullable
private static String getValidProvider(LocationManager locationManager, boolean highAccuracy) {
  String provider =
      highAccuracy ? LocationManager.GPS_PROVIDER : LocationManager.NETWORK_PROVIDER;
  if (!locationManager.isProviderEnabled(provider)) {
    provider = provider.equals(LocationManager.GPS_PROVIDER)
        ? LocationManager.NETWORK_PROVIDER
        : LocationManager.GPS_PROVIDER;
    if (!locationManager.isProviderEnabled(provider)) {
      return null;
    }
  }
  return provider;
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:15,代码来源:LocationModule.java

示例8: getCityByLocation

import android.location.LocationManager; //导入方法依赖的package包/类
void getCityByLocation() {
    locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

    if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.ACCESS_FINE_LOCATION)) {
            // Explanation not needed, since user requests this himself

        } else {
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                    MY_PERMISSIONS_ACCESS_FINE_LOCATION);
        }

    } else if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER) ||
            locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        progressDialog = new ProgressDialog(this);
        progressDialog.setMessage(getString(R.string.getting_location));
        progressDialog.setCancelable(false);
        progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.dialog_cancel), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                try {
                    locationManager.removeUpdates(MainActivity.this);
                } catch (SecurityException e) {
                    e.printStackTrace();
                }
            }
        });
        progressDialog.show();
        if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
            locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
        }
        if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
            locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
        }
    } else {
        showLocationSettingsDialog();
    }
}
 
开发者ID:hichemcesar24,项目名称:Weather-Android,代码行数:41,代码来源:MainActivity.java

示例9: getLocation

import android.location.LocationManager; //导入方法依赖的package包/类
public Location getLocation() {
    try {
        locationManager = (LocationManager) mContext
                .getSystemService(LOCATION_SERVICE);
        // getting GPS status
        isGPSEnabled = locationManager
                .isProviderEnabled(LocationManager.GPS_PROVIDER);
        // getting network status
        isNetworkEnabled = locationManager
                .isProviderEnabled(LocationManager.NETWORK_PROVIDER);
        if (!isGPSEnabled && !isNetworkEnabled) {
            showSettingsAlert();
        }
        else {
            this.canGetLocation = true;
            if (isNetworkEnabled) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    if (mContext.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                        // TODO: Consider calling
                        //    ActivityCompat#requestPermissions
                        // here to request the missing permissions, and then overriding
                        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
                        //                                          int[] grantResults)
                        // to handle the case where the user grants the permission. See the documentation
                        // for ActivityCompat#requestPermissions for more details.
                        return null;
                    }
                }
                locationManager.requestLocationUpdates(
                        LocationManager.NETWORK_PROVIDER,
                        MIN_TIME_BW_UPDATES,
                        MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                Log.d("Network", "Network");
                if (locationManager != null) {
                    location = locationManager
                            .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
                    if (location != null) {
                        latitude = location.getLatitude();
                        longitude = location.getLongitude();
                    }
                }
            }
            // if GPS Enabled get lat/long using GPS Services
            if (isGPSEnabled) {
                if (location == null) {
                    locationManager.requestLocationUpdates(
                            LocationManager.GPS_PROVIDER,
                            MIN_TIME_BW_UPDATES,
                            MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                    Log.d("GPS Enabled", "GPS Enabled");
                    if (locationManager != null) {
                        location = locationManager
                                .getLastKnownLocation(LocationManager.GPS_PROVIDER);
                        if (location != null) {
                            latitude = location.getLatitude();
                            longitude = location.getLongitude();
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    mLastestLocation = new LatLng(latitude, longitude);
    return location;
}
 
开发者ID:sega4revenge,项目名称:Sega,代码行数:68,代码来源:GPSTracker.java

示例10: getLocation

import android.location.LocationManager; //导入方法依赖的package包/类
public Location getLocation() {
    try {
        locationManager = (LocationManager) mContext
                .getSystemService(LOCATION_SERVICE);

        // getting GPS status
        isGPSEnabled = locationManager
                .isProviderEnabled(LocationManager.GPS_PROVIDER);

        // getting network status
        isNetworkEnabled = locationManager
                .isProviderEnabled(LocationManager.NETWORK_PROVIDER);

        if (isGPSEnabled && isNetworkEnabled) {
            this.canGetLocation = true;
            if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
                ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {

                AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);
                alertDialog.setTitle("GPS permissions");
                alertDialog.setMessage("Please grant the App permissions to use GPS.");
            }
            if (isNetworkEnabled) {
                locationManager.requestLocationUpdates(
                        LocationManager.NETWORK_PROVIDER,
                        MIN_TIME_BW_UPDATES,
                        MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                Log.d("Network", "Network Enabled");
                if (locationManager != null) {
                    location = locationManager
                            .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
                    if (location != null) {
                        latitude = location.getLatitude();
                        longitude = location.getLongitude();
                    }
                }
            }
            // if GPS Enabled get lat/long using GPS Services
            if (isGPSEnabled) {
                if (location == null) {
                    locationManager.requestLocationUpdates(
                            LocationManager.GPS_PROVIDER,
                            MIN_TIME_BW_UPDATES,
                            MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                    Log.d("GPS", "GPS Enabled");
                    if (locationManager != null) {
                        location = locationManager
                                .getLastKnownLocation(LocationManager.GPS_PROVIDER);
                        if (location != null) {
                            latitude = location.getLatitude();
                            longitude = location.getLongitude();
                        }
                    }
                }
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    return location;
}
 
开发者ID:hpi-xnor,项目名称:android-image-classification,代码行数:64,代码来源:GPSTracker.java

示例11: getLocation

import android.location.LocationManager; //导入方法依赖的package包/类
public Location getLocation()
{
    try
    {
        locationManager = (LocationManager)getSystemService(LOCATION_SERVICE);

        //getting GPS status
        isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);

        //getting network status
        isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

        if (!isGPSEnabled && !isNetworkEnabled)
        {
            // no network provider is enabled
        }
        else
        {
            this.canGetLocation = true;

            //First get location from Network Provider
            if (isNetworkEnabled)
            {
                locationManager.requestLocationUpdates(
                        LocationManager.NETWORK_PROVIDER,
                        MIN_TIME_BW_UPDATES,
                        MIN_DISTANCE_CHANGE_FOR_UPDATES, this);

                Log.d("Network", "Network");

                if (locationManager != null)
                {
                    location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
                    updateGPSCoordinates();
                }
            }

            //if GPS Enabled get lat/long using GPS Services
            if (isGPSEnabled)
            {
                if (location == null)
                {
                    locationManager.requestLocationUpdates(
                            LocationManager.GPS_PROVIDER,
                            MIN_TIME_BW_UPDATES,
                            MIN_DISTANCE_CHANGE_FOR_UPDATES, this);

                    Log.d("GPS Enabled", "GPS Enabled");

                    if (locationManager != null)
                    {
                        location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
                        updateGPSCoordinates();
                    }
                }
            }
        }
    }
    catch (Exception e)
    {
        //e.printStackTrace();
        Log.e("Error : Location", "Impossible to connect to LocationManager", e);
    }

    return location;
}
 
开发者ID:SkylineLabs,项目名称:FindX,代码行数:67,代码来源:MyLocation.java

示例12: isGPSEnabled

import android.location.LocationManager; //导入方法依赖的package包/类
public static boolean isGPSEnabled(Context mContext) {
    LocationManager locationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
    return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
}
 
开发者ID:CityZenApp,项目名称:Android-Development,代码行数:5,代码来源:DeviceUtils.java

示例13: getLocation

import android.location.LocationManager; //导入方法依赖的package包/类
public Location getLocation()
{
    try
    {
        locationManager = (LocationManager) mContext.getSystemService(LOCATION_SERVICE);

        //getting GPS status
        isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);

        //getting network status
        isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

        if (!isGPSEnabled && !isNetworkEnabled)
        {
            // no network provider is enabled
        }
        else
        {
            this.canGetLocation = true;

            //First get location from Network Provider
            if (isNetworkEnabled)
            {
                locationManager.requestLocationUpdates(
                        LocationManager.NETWORK_PROVIDER,
                        MIN_TIME_BW_UPDATES,
                        MIN_DISTANCE_CHANGE_FOR_UPDATES, this);

                Log.d("Network", "Network");

                if (locationManager != null)
                {
                    location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
                    updateGPSCoordinates();
                }
            }

            //if GPS Enabled get lat/long using GPS Services
            if (isGPSEnabled)
            {
                if (location == null)
                {
                    locationManager.requestLocationUpdates(
                            LocationManager.GPS_PROVIDER,
                            MIN_TIME_BW_UPDATES,
                            MIN_DISTANCE_CHANGE_FOR_UPDATES, this);

                    Log.d("GPS Enabled", "GPS Enabled");

                    if (locationManager != null)
                    {
                        location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
                        updateGPSCoordinates();
                    }
                }
            }
        }
    }
    catch (Exception e)
    {
        //e.printStackTrace();
        Log.e("Error : Location", "Impossible to connect to LocationManager", e);
    }

    return location;
}
 
开发者ID:SkylineLabs,项目名称:FindX,代码行数:67,代码来源:GPSTracker.java

示例14: onPreExecute

import android.location.LocationManager; //导入方法依赖的package包/类
@Override
protected void onPreExecute() {
    mLocationListener = new mLocationListener();
    mLocationManager =
            (LocationManager) getSystemService(Context.LOCATION_SERVICE);


    mLocationManager.requestLocationUpdates(
            LocationManager.NETWORK_PROVIDER, 0, 0,
            mLocationListener);




    if (!mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {

        Toast.makeText(FieldModeActivity.this, getResources().getString(R.string.location_disabled), Toast.LENGTH_SHORT).show();
        this.cancel(true);
        return;
    }





    pb_location.setIndeterminate(true);
    pb_location.setVisibility(View.VISIBLE);
}
 
开发者ID:feup-infolab,项目名称:labtablet,代码行数:29,代码来源:FieldModeActivity.java

示例15: isGpsEnabled

import android.location.LocationManager; //导入方法依赖的package包/类
/**
 * 判断Gps是否可用
 *
 * @return {@code true}: 是<br>{@code false}: 否
 */
public static boolean isGpsEnabled() {
    LocationManager lm = (LocationManager) Utils.getContext().getSystemService(Context.LOCATION_SERVICE);
    return lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
}
 
开发者ID:pan2yong22,项目名称:AndroidUtilCode-master,代码行数:10,代码来源:LocationUtils.java


注:本文中的android.location.LocationManager.isProviderEnabled方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。