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.artur.softwareproject.GpsService.java

@Override
public void onCreate() {
    super.onCreate();
    Log.d(TAG, "GpsService was created.");

    gpsStatus = false;/*from www  . jav  a  2s  .  c o m*/

    gpsManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    checkPermission("android.permission.ACCESS_FINE_LOCATION", 1, 0);

    gpsManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);

    Thread gpsStatusThread = new Thread(this);
    gpsStatusThread.start();
}

From source file:com.net.rmopenmenu.MainActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

    setContentView(R.layout.fragment_tabs_pager);

    mTabHost = (TabHost) findViewById(android.R.id.tabhost);
    mTabHost.setup();//from   www  . ja  v  a  2s.  c  o  m

    mViewPager = (ViewPager) findViewById(R.id.pager);

    mTabsAdapter = new TabsAdapter(this, mTabHost, mViewPager);

    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    Bundle b1 = new Bundle();
    b1.putBoolean("menu", true);

    Bundle b2 = new Bundle();
    b2.putBoolean("menu", false);

    mTabsAdapter.addTab(mTabHost.newTabSpec("menu").setIndicator("Menu"), MenuFragment.class, b1);
    mTabsAdapter.addTab(mTabHost.newTabSpec("restaurant").setIndicator("Restaurant"), MenuFragment.class, b2);
    if (savedInstanceState != null) {
        mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab"));
    }

    // Acquire a reference to the system Location Manager
    locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

    // Define a listener that responds to location updates
    locationListener = new LocationListener() {
        public void onStatusChanged(String provider, int status, Bundle extras) {
        }

        public void onProviderEnabled(String provider) {
        }

        public void onProviderDisabled(String provider) {
        }

        @Override
        public void onLocationChanged(Location location) {
            SharedPreferences.Editor editor = prefs.edit();

            editor.putInt("lat", (int) (location.getLatitude() * 1000000));
            editor.putInt("lon", (int) (location.getLongitude() * 1000000));

            editor.commit();
        }
    };

    // Register the listener with the Location Manager to receive location updates
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
}

From source file:geotag.example.sbickt.BicksActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.bicks_view);

    Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/LiteraEF-Medium.otf");
    editTextBicks = (EditText) findViewById(R.id.edit_text_bicks);
    buttonBicks = (ImageButton) findViewById(R.id.button_bicks);
    radioGroupCategory = (RadioGroup) findViewById(R.id.radio_group_category);
    radioButtonPrivate = (RadioButton) findViewById(R.id.radio_category_private);
    radioButtonFriends = (RadioButton) findViewById(R.id.radio_category_friends);
    radioButtonPublic = (RadioButton) findViewById(R.id.radio_category_public);

    editTextBicks.setTypeface(tf);//from   w  w  w  .  ja v a  2s. c om
    editTextBicks.setEnabled(false);
    buttonBicks.setEnabled(false);
    radioButtonPrivate.setTag("private");
    radioButtonFriends.setTag("protected");
    radioButtonPublic.setTag("public");

    radioGroupCategory.setOnCheckedChangeListener(radioGroupCategoryOnCheckedChangeListener);
    buttonBicks.setOnClickListener(buttonBicksOnClickListener);

    locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    currentLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 10, locationListener);

}

From source file:com.hoccer.api.android.LinccLocationManager.java

public void activate() {

    mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, this);

    if (mNetworkProviderAvailable) {

        mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 1, this);
    }/*from  ww  w. j  a  v a 2  s .c  o m*/
}

From source file:com.yammy.meter.MainActivity.java

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

    setContentView(R.layout.isvo_activity_main);
    lat = (TextView) this.findViewById(R.id.main_lat);
    longi = (TextView) this.findViewById(R.id.main_long);
    nopol = (TextView) this.findViewById(R.id.main_nopol);
    jarak = (TextView) this.findViewById(R.id.main_jarak);
    start = (Button) this.findViewById(R.id.buttonStartRec);
    stop = (Button) this.findViewById(R.id.buttonStopRec);
    reset = (Button) this.findViewById(R.id.buttonClrMapMain);
    stop.setEnabled(false);//ww w  .j  a  v  a 2  s.c  o  m
    reset.setEnabled(false);
    Location location = null;

    getVehVal();

    int result = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
    if (result != ConnectionResult.SUCCESS) {
        GooglePlayServicesUtil.getErrorDialog(result, MainActivity.this, 1).show();
    } else {
        /**
         * try to get current location via GPS
         * pending : path recording using Polyline & get length
         */

        locationManager = (LocationManager) this.getSystemService(LOCATION_SERVICE);
        boolean enabledGPS = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
        if (!enabledGPS) {
            requestGPS();
            finish();
        }

        map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map_main)).getMap();
        GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(getBaseContext());

        map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
        map.setIndoorEnabled(false);

        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 0, this);
        location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

        try {
            user_pos = new LatLng(location.getLatitude(), location.getLongitude());
            if (location != null
                    && location.getTime() > Calendar.getInstance().getTimeInMillis() - 2 * 60 * 1000) {
                Toast.makeText(getApplicationContext(),
                        "Current Location : " + location.getLatitude() + "," + location.getLongitude(),
                        Toast.LENGTH_LONG).show();
                drawMarker(location);
            } else {
                locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, this);
                drawMarker(location);
            }
        } catch (NullPointerException e) {
            //requestGPS();
        }
    }

    start.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            recording = true;
            Toast.makeText(getBaseContext(), "Mulai merekam perjalanan", Toast.LENGTH_SHORT).show();
            stop.setEnabled(true);
            start.setEnabled(false);
            reset.setEnabled(false);
            jarakTotal = 0.0;
        }
    });
    stop.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            recording = false;
            Toast.makeText(getBaseContext(), "Selesai merekam perjalanan", Toast.LENGTH_SHORT).show();
            Toast.makeText(getBaseContext(), "Perjalanan terakhir " + jarakTotal + " m", Toast.LENGTH_SHORT)
                    .show();
            /**
             * then save to database
             */
            try {
                dbHelper = new MySQLHelper(getApplicationContext());
                SQLiteDatabase db = dbHelper.getWritableDatabase();
                ContentValues simpan = new ContentValues();
                simpan.put("id_kendaraan", idkendaraan);
                simpan.put("jarak", jarakTotal);
                db.insert("perjalanan", null, simpan);
                Toast.makeText(getBaseContext(), "Perjalanan tersimpan", Toast.LENGTH_SHORT).show();
                db.close();
            } catch (Exception e) {
                Toast.makeText(getBaseContext(), "Tidak bisa menyimpan perjalanan", Toast.LENGTH_SHORT).show();
            }

            //partial reset
            stop.setEnabled(false);
            start.setEnabled(true);
            reset.setEnabled(true);
            jarakTotal = 0.0;

            checkJarak();
        }
    });
    reset.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            map.clear();
            jarakTotal = 0.0;
            jarak.setText(null);
        }
    });
    checkJarak();
}

From source file:com.qi.airstat.BluetoothLeService.java

@Override
public void onCreate() {
    try {/*w  w  w  .  j a v a  2s .co m*/
        locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1, 1, locationListener);
    } catch (SecurityException exception) {
        exception.printStackTrace();
    }
}

From source file:com.example.demo_dv_fuse.MapScreen.java

/**
 * @see android.app.Activity#onCreate(android.os.Bundle)
 *//*from  w w  w .  j a v  a 2 s .co  m*/
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.map_screen);
    this.map = ((MapFragment) getFragmentManager().findFragmentById(R.id.mapView)).getMap();
    this.map.setMapType(GoogleMap.MAP_TYPE_NORMAL);

    final int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());

    if (status == ConnectionResult.SUCCESS) { // Google Play Services is available
        // Enabling MyLocation Layer of Google Map
        this.map.setMyLocationEnabled(true);

        // Getting LocationManager object from System Service LOCATION_SERVICE
        final LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

        // Creating a criteria object to retrieve provider
        final Criteria criteria = new Criteria();

        // Getting the name of the best provider
        final String provider = locationManager.getBestProvider(criteria, true);

        // Getting Current Location
        final Location location = locationManager.getLastKnownLocation(provider);

        if (location != null) {
            onLocationChanged(location);
            //            } else {
            //                final String coordinates[] = {"1.352566007", "103.78921587"};
            //                final double lat = Double.parseDouble(coordinates[0]);
            //                final double lng = Double.parseDouble(coordinates[1]);
            //
            //                // Creating a LatLng object for the current location
            //                LatLng latLng = new LatLng(lat, lng);
            //
            //                // Showing the current location in Google Map
            //                this.map.moveCamera(CameraUpdateFactory.newLatLng(latLng));
            //                this.map.animateCamera(CameraUpdateFactory.zoomTo(15));
        }
        boolean enabledGPS = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
        boolean enabledWiFi = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

        // Check if enabled and if not send user to the GSP settings
        // Better solution would be to display a dialog and suggesting to 
        // go to the settings
        if (!enabledGPS || !enabledWiFi) {
            Toast.makeText(this, "GPS signal not found", Toast.LENGTH_LONG).show();
            Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            startActivity(intent);
        }
        locationManager.requestLocationUpdates(provider, 20000, 0, this);
    } else { // Google Play Services are not available
        final int requestCode = 10;
        final Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
        dialog.show();
    }
}

From source file:com.vrjco.v.demo.MainActivity.java

private void startLogging(boolean check) {
    if (check) {//www  . j a  v a  2 s . com
        //checking if gps and network is ON.
        gpsok = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
        networkok = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
        if (ActivityCompat.checkSelfPermission(this,
                Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                && ActivityCompat.checkSelfPermission(this,
                        Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            Toast.makeText(this, "LOCATION PROVIDER PERMISSIONS NOT GRANTED", Toast.LENGTH_LONG).show();
            return;
        }
        checking = true;
        //checking every 100 miliSec and minDistance change 0
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, logLocationListener);
        lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, logLocationListener);
        if (gpsok && networkok) {
            Toast.makeText(this, "GPS and NETWORK PROVIDER Found!!", Toast.LENGTH_SHORT).show();
            location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
            location = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
            if (location != null) {
                lat = location.getLatitude();
                longi = location.getLongitude();
                tvlat.setText(Double.toString(lat));
                tvlongi.setText(Double.toString(longi));
            }

        } else {
            Toast.makeText(this, "LOCATION PROVIDER NOT AVAILABLE", Toast.LENGTH_LONG).show();
        }
    } else {
        lm.removeUpdates(logLocationListener);
        checking = false;
    }
}

From source file:com.rsamadhan.MainActivity.java

@Override
protected void onResume() {
    super.onResume();
    LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
    boolean enabled = service.isProviderEnabled(LocationManager.GPS_PROVIDER);

    // check if enabled and if not send user to the GSP settings
    // Better solution would be to display a dialog and suggesting to
    // go to the settings
    if (!enabled) {
        showGPSDialog();//from  ww  w . ja va  2s . c o  m
    }
}

From source file:com.precisionag.waterplane.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.field);
    MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
    GoogleMap map = mapFragment.getMap();
    map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
    map.setMyLocationEnabled(true);/* w  w w . j  a v  a  2 s.  com*/
    map.setOnMapClickListener(this);
    map.setOnMarkerClickListener(onMarkerClickListener);

    field = new Field(bitmap, new LatLng(0.0, 0.0), new LatLng(0.0, 0.0), 0.0, 0.0);
    markers = new ArrayList<Marker>();
    mode = 0;

    readDataFile(field);
    prevoverlay = field.createOverlay(map);
    configSeekbar(field, prevoverlay);
    LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
}