Example usage for android.location LocationManager GPS_PROVIDER

List of usage examples for android.location LocationManager GPS_PROVIDER

Introduction

In this page you can find the example usage for android.location LocationManager GPS_PROVIDER.

Prototype

String GPS_PROVIDER

To view the source code for android.location LocationManager GPS_PROVIDER.

Click Source Link

Document

Name of the GPS location provider.

Usage

From source file:com.kinvey.samples.citywatch.CityWatch.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Logger.getLogger(HttpTransport.class.getName()).setLevel(LOGGING_LEVEL);

    kinveyClient = ((CityWatchApplication) getApplication()).getClient();

    if (!kinveyClient.user().isUserLoggedIn()) {
        login();/* w  w  w  .j  a  v a2  s  . c o m*/
    } else {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        // Note there is no call to SetContentView(...) here.
        // Check out onTabSelected()-- the selected tab and associated
        // fragment
        // is
        // given
        // android.R.id.content as it's parent view, which *is* the content
        // view. Basically, this approach gives the fragments under the tabs
        // the
        // complete window available to our activity without any unnecessary
        // layout inflation.
        setUpTabs();

        curEntity = new CityWatchEntity();
        nearbyAddress = new ArrayList<Address>();
        nearbyEntities = new ArrayList<CityWatchEntity>();

        locationmanager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        locationmanager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000, 100, this);

        if (Geocoder.isPresent()) {
            geocoder = new Geocoder(this);
        }

        // get last known location for a quick, rough start. Try GPS, if
        // that
        // fails, try network. If that fails wait for fresh data
        lastKnown = locationmanager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        if (lastKnown == null) {
            lastKnown = locationmanager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        }
        if (lastKnown == null) {
            // if the device has never known it's location, start at 0...?
            lastKnown = new Location(TAG);
            lastKnown.setLatitude(0.0);
            lastKnown.setLongitude(0.0);
        }
        Log.i(TAG, "lastKnown -> " + lastKnown.getLatitude() + ", " + lastKnown.getLongitude());
        setLocationInEntity(lastKnown);
    }

}

From source file:com.platform.GeoLocationManager.java

public void startGeoSocket(Session sess) {
    session = sess;//from   ww  w.j av a2s . c o m

    final MainActivity app = MainActivity.app;
    if (app == null)
        return;
    final LocationManager locationManager = (LocationManager) app.getSystemService(Context.LOCATION_SERVICE);

    app.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (ActivityCompat.checkSelfPermission(app,
                    Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                    && ActivityCompat.checkSelfPermission(app,
                            Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                RuntimeException ex = new RuntimeException("startGeoSocket, can't happen");
                Log.e(TAG, "run: startGeoSocket, can't happen");
                FirebaseCrash.report(ex);
                return;
            }
            locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 0,
                    socketLocationListener);
            locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0,
                    socketLocationListener);

        }
    });
}

From source file:at.ac.tuwien.caa.docscan.camera.LocationHandler.java

public Location getLocation() {

    if (mLocation != null)
        return mLocation;
    else {//  w  w  w  .  j  av a  2s  . co m
        //            If no location has been found yet, use the last known location as a fallback:
        if (ActivityCompat.checkSelfPermission(mContext,
                Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
            Location l1 = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
            Location l2 = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

            if (l1 != null && l2 != null) {
                if (l1.getAccuracy() > l2.getAccuracy())
                    return l1;
                else
                    return l2;
            } else {
                if (l1 != null)
                    return l1;
                else
                    return l2;
            }
        }
    }

    //        If the user has given no permission to access location return nothing:
    return null;
}

From source file:com.example.get_location.Get_location.java

@Override
protected void onStart() {
    super.onStart();

    // Check if the GPS setting is currently enabled on the device.
    // This verification should be done during onStart() because the system calls this method
    // when the user returns to the activity, which ensures the desired location provider is
    // enabled each time the activity resumes from the stopped state.
    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    final boolean gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);

    if (!gpsEnabled) {
        // Build an alert dialog here that requests that the user enable
        // the location services, then when the user clicks the "OK" button,
        // call enableLocationSettings()
    }// ww  w  . ja v a 2 s  .  c  om
}

From source file:net.openwatch.acluaz.fragment.FormFragment.java

public JSONObject toJson(ViewGroup container, JSONObject json) {
    String TAG = "FormFragment-ToJSON";
    if (container == null) {
        Log.e(TAG, "null container passed to toJson");
        return new JSONObject();
    }/*from   www . j  av  a2 s  . com*/

    if (json == null)
        json = new JSONObject();
    View view;
    for (int x = 0; x < container.getChildCount(); x++) {
        view = container.getChildAt(x);

        if (EditText.class.isInstance(view)) {
            if (view.getTag() != null) {
                if (((EditText) view).getText().toString().compareTo("") == 0)
                    continue; // skip blank input
                try {
                    Log.i(TAG, "Mapping: " + view.getTag().toString() + " value: "
                            + ((EditText) view).getText().toString());
                    if (view.getTag().toString().compareTo(getString(R.string.zipcode_tag)) == 0)
                        json.put(view.getTag().toString(),
                                Integer.parseInt(((EditText) view).getText().toString()));
                    else
                        json.put(view.getTag().toString(), ((EditText) view).getText().toString());
                } catch (JSONException e) {
                    Log.e(TAG, "Error jsonifying text input");
                    e.printStackTrace();
                }

            }
        } else if (CompoundButton.class.isAssignableFrom(view.getClass())) {
            if (view.getTag() != null) {
                // if location toggle, bundle location
                if (((String) view.getTag()).compareTo(getString(R.string.device_location_tag)) == 0
                        && view.getTag(R.id.view_tag) != null) {
                    if (((CompoundButton) view).isChecked()) {
                        try {
                            json.put(getString(R.string.device_lat),
                                    ((Location) view.getTag(R.id.view_tag)).getLatitude());
                            json.put(getString(R.string.device_lon),
                                    ((Location) view.getTag(R.id.view_tag)).getLongitude());
                        } catch (JSONException e) {
                            Log.e(TAG, "Error jsonifying toggle input");
                            e.printStackTrace();
                        }
                    }
                } else if (((String) view.getTag()).compareTo(getString(R.string.device_location_tag)) == 0
                        && view.getTag(R.id.view_tag) == null) {
                    // no location tagged, get last known
                    LocationManager lm = (LocationManager) container.getContext()
                            .getSystemService(Context.LOCATION_SERVICE);
                    Location last = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
                    try {
                        json.put(getString(R.string.device_lat), last.getLatitude());
                        json.put(getString(R.string.device_lon), last.getLongitude());
                    } catch (JSONException e) {
                        Log.e(TAG, "Error jsonifying last location");
                        e.printStackTrace();
                    } catch (NullPointerException e2) {
                        Log.e(TAG, "No current or historical location info on this device");
                    }
                }

            }
        }

        // combine date and time fields into a single datetime
        if (json.has(getString(R.string.date_tag)) && json.has(getString(R.string.time_tag))) {
            Log.i(TAG, "found date and time tag, let's smush 'em");
            try {
                //TESTING
                //String datetime = combineDateAndTime(json.getString(getString(R.string.date_tag)), json.getString(getString(R.string.time_tag)));
                //Log.i(TAG,"datetime: " + datetime);
                json.put(getString(R.string.date_tag),
                        combineDateAndTime(json.getString(getString(R.string.date_tag)),
                                json.getString(getString(R.string.time_tag))));
                Log.i(TAG, json.toString());
                //json.remove(getString(R.string.date_tag));
                json.remove(getString(R.string.time_tag));
            } catch (JSONException e) {
                Log.e(TAG, "Error creating json datetime field from date and time");
                e.printStackTrace();
            }
        }

    }
    Log.i(TAG, "toJson: " + json.toString());
    return json;

}

From source file:com.example.mapdemo.MyLocationDemoActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    instance = this;
    super.onCreate(savedInstanceState);

    setContentView(R.layout.my_location_demo);

    ButterKnife.bind(this);

    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(map);
    mapFragment.getMapAsync(this);

    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (ActivityCompat.checkSelfPermission(this,
            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;/*  www .j av  a  2 s . c  o  m*/
    }
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, new PositionListener());

    alarm = RingtoneManager.getRingtone(getApplicationContext(),
            RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM));

    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            createDialogForProgrammedStop();
            handler.postDelayed(this, Constants.TIME);
        }
    }, Constants.TIME);

}

From source file:com.yammy.meter.map.MainMapBengkel.java

@Override
protected void onResume() {
    super.onResume();
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 400, 1, this);
}

From source file:httbdd.cse.nghiatran.halofind.fragment.MainFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.demo, container, false);
    mSlidingUpPanelLayout = (SlidingUpPanelLayout) rootView.findViewById(R.id.slidingLayout);
    mSlidingUpPanelLayout.setEnableDragViewTouchEvents(true);

    int mapHeight = getResources().getDimensionPixelSize(R.dimen.map_height);
    mSlidingUpPanelLayout.setPanelHeight(mapHeight); // you can use different height here

    mSlidingUpPanelLayout.setPanelSlideListener((SlidingUpPanelLayout.PanelSlideListener) getActivity());
    mapView = (MapView) rootView.findViewById(R.id.mapView);
    //        lat = getIntent().getDoubleExtra("lat", lat);
    //        longt = getIntent().getDoubleExtra("long", longt);
    //        addresss = getIntent().getStringExtra("address");
    //        title = getIntent().getStringExtra("title");
    mapView.onCreate(savedInstanceState);
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);/*w w  w.j  av  a  2  s .c om*/
    locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
    updateValuesFromBundle(savedInstanceState);
    if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
        alert.setMessage("GPS is disabled in your device. Would you like to enable it?");
        alert.setPositiveButton("Cancel", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        alert.setNegativeButton("Go to Settings", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                Intent I = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                startActivity(I);
            }
        });
        AlertDialog al_gps = alert.create();
        al_gps.show();
    } else {
        if (ActivityCompat.checkSelfPermission(getActivity(),
                Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                && ActivityCompat.checkSelfPermission(getActivity(),
                        Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
                    (android.location.LocationListener) this);
        }
    }
    mapView.getMapAsync(this);
    createLocationRequest();
    return rootView;
}

From source file:com.m2dl.mini_projet.mini_projet_android.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    if (screenIsLarge()) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    } else {//from w  w w .  java 2s .co  m
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }

    myPhotoMarkers = new HashMap<>();

    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (ActivityCompat.checkSelfPermission(this,
            Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        return;
    }
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000, 5, this);

    if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        buildAlertMessageNoGps();
    } else {
        isGPSOn = true;
    }

    coordLat = 0.0;
    coordLong = 0.0;

    FloatingActionButton fabPhoto = (FloatingActionButton) findViewById(R.id.fabPhoto);
    fabPhoto.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            takePhoto(view);
        }
    });

    FloatingActionButton fabTagSelect = (FloatingActionButton) findViewById(R.id.fabTagSelect);
    fabTagSelect.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            selectTags();
        }
    });

    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);

    pointInteretManager = new PointInteretManager(this);

    // Init tag list
    allTags = new TreeSet<>();
    selectedTags = new TreeSet<>();
}