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.platform.GeoLocationManager.java

public void getOneTimeGeoLocation(Continuation cont, Request req) {
    this.continuation = cont;
    this.baseRequest = req;
    final MainActivity app = MainActivity.app;
    if (app == null)
        return;/*from www. j  av  a  2  s  . c  om*/
    locationManager = (LocationManager) app.getSystemService(Context.LOCATION_SERVICE);
    if (locationManager == null) {
        Log.e(TAG, "getOneTimeGeoLocation: locationManager is null!");
        return;
    }
    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("getOneTimeGeoLocation, can't happen");
                Log.e(TAG, "run: getOneTimeGeoLocation, can't happen");
                FirebaseCrash.report(ex);
                return;
            }
            locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
            locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
        }
    });

}

From source file:com.pansapiens.occyd.NewPost.java

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

    // start polling location ASAP, so it can be accurate by the time
    // the post button is pressed
    locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    LocationUpdater locupdater = new LocationUpdater(locationManager);
    locupdater.startUpdating();//  ww  w .  jav a  2 s  .  c  o m

    setContentView(R.layout.newpost);

    final Button post_button = (Button) findViewById(R.id.post_button);
    post_button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            String result_code = null;

            // get text from textboxes and encode it to be URL safe 
            String desc = ((TextView) findViewById(R.id.desc_txt)).getText().toString();
            String tags = ((TextView) findViewById(R.id.tags_txt)).getText().toString();
            try {
                desc = URLEncoder.encode(desc, "UTF-8");
                tags = URLEncoder.encode(tags, "UTF-8");
            } catch (UnsupportedEncodingException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

            // current API URL scheme uses commas between tags
            tags = tags.replace("+", ",");

            /*
               // turn space delimited tag list into a + delimited list, for the URL
               String[] tag_array = tags_txt.split(" ");
               String tags = null;
               for (int i = 0; i < tag_array.length; i++) {
                  tags += tag_array[i];
                  if (i < tag_array.length-1) {
             tags += "+";
                  }
               }
               */

            // TODO: put an accuracy check in here ... don't post if
            //         the accuracy is too low ... 
            //       (or give a "really post with inaccurate location ?" warning)
            Location here = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
            double lat = here.getLatitude();
            double lon = here.getLongitude();

            //Toast.makeText(NewPost.this, "Posting ...",
            //        Toast.LENGTH_LONG).show();

            try {
                String BASEURL = getString(R.string.occyd_server);
                String urlstr = String.format("%s/v1/posts/add?ll=%f,%f&desc=%s&tags=%s&link=%s", BASEURL, lat,
                        lon, desc, tags, BASEURL);
                final URL url = new URL(urlstr);

                TextView tx = (TextView) findViewById(R.id.new_post_title);
                tx.setText(url.toString());

                // run http fetch in a thread, with 
                // 'posting' dialog
                final Thread tr = new Thread() {
                    @Override
                    public void run() {
                        handle_result.post(mDisplayPosting);
                        UrlFetch fetcher = new UrlFetch(url, handle_result);
                        fetcher.fetch();
                        handle_result.post(mDismissPosting);
                    }
                };
                tr.start();

            } catch (MalformedURLException e) {
                Toast.makeText(NewPost.this, "FAIL: Malformed URL.", Toast.LENGTH_LONG).show();
            } catch (IOException e) {
                Toast.makeText(NewPost.this, "FAIL: http fetch failed.", Toast.LENGTH_LONG).show();
            }
        }
    });
}

From source file:com.fallahpoor.infocenter.fragments.gps.GpsFragment.java

public boolean hasGpsFeature() {

    LocationManager locationManager = (LocationManager) getActivity()
            .getSystemService(Context.LOCATION_SERVICE);

    if (locationManager == null) {
        return false;
    }/*from   w ww  .j ava  2 s.c o  m*/

    Iterator<String> iterator = locationManager.getAllProviders().iterator();
    String provider;

    while (iterator.hasNext()) {
        provider = iterator.next();
        if (provider.equals(LocationManager.GPS_PROVIDER)) {
            return true;
        }
    }

    return false;

}

From source file:com.nextgis.mobile.forms.CameraFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    setRetainInstance(true);//from   ww w . j  a v  a  2  s. co  m

    View view = inflater.inflate(R.layout.camfragment, container, false);

    Button button = (Button) view.findViewById(R.id.insert_take_photo);
    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            onCapturePhoto();
        }
    });

    ListView photoList = (ListView) view.findViewById(R.id.poi_photos_list);

    adapter = new SimpleAdapter(view.getContext(), listItems, R.layout.row, new String[] { IMG_NAME, IMG_ROT, },
            new int[] { R.id.image_name, R.id.image_rotation });

    photoList.setAdapter(adapter);

    final LocationManager locationManager = (LocationManager) getActivity()
            .getSystemService(Context.LOCATION_SERVICE);

    if (currentLocation == null) {
        currentLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        if (currentLocation == null) {
            currentLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        }
    }
    long now = System.currentTimeMillis();
    declination = CompassFragment.getDeclination(currentLocation, now);

    sensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE);

    return view;
}

From source file:com.djit.mixfader.sample.BaseActivity.java

/**
 * Check if the user needs to enable the location.
 * <p/>//  ww w .  java  2  s  .c  o  m
 * Since Android Marshmallow, the location is required to scan for bluetooth devices.
 *
 * @return Return true is the location need to be enable, false otherwise.
 */
private static boolean needToEnableLocation(final Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        return false;
    } else {
        final LocationManager locationManager = (LocationManager) context.getSystemService(LOCATION_SERVICE);
        return !locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)
                && !locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    }
}

From source file:ti.modules.titanium.geolocation.TiLocation.java

public boolean getLocationServicesEnabled() {
    List<String> providerNames = locationManager.getProviders(true);

    if (Log.isDebugModeEnabled()) {
        Log.i(TAG, "Enabled location provider count: " + providerNames.size());

        for (String providerName : providerNames) {
            Log.i(TAG, providerName + " service available");
        }//ww w.  j  ava  2  s .c o  m
    }

    // don't count the passive provider
    for (String name : providerNames) {
        if (name.equals(LocationManager.NETWORK_PROVIDER) || name.equals(LocationManager.GPS_PROVIDER)) {
            return true;
        }
    }

    return false;
}

From source file:com.samknows.measurement.schedule.datacollection.LocationDataCollector.java

@Override
public void start(TestContext tc) {
    super.start(tc);
    locations = Collections.synchronizedList(new ArrayList<Location>());
    manager = (LocationManager) tc.getSystemService(Context.LOCATION_SERVICE);

    locationType = AppSettings.getInstance().getLocationServiceType();
    //if the provider in the settings is gps but the service is not enable fail over to network provider
    if (locationType == LocationType.gps && !manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        locationType = LocationType.network;
    }//from   ww w  .  j av a2 s .c  o m

    if (locationType != LocationType.gps && locationType != LocationType.network) {
        throw new RuntimeException("unknown location type: " + locationType);
    }

    String provider = locationType == LocationType.gps ? LocationManager.GPS_PROVIDER
            : LocationManager.NETWORK_PROVIDER;

    if (getLastKnown) {
        lastKnown = manager.getLastKnownLocation(provider);
        if (lastKnown != null) {
            data.add(new LocationData(true, lastKnown, locationType));
            lastKnownLocation = locationToDCSString("LASTKNOWNLOCATION", lastKnown);
        }
    }
    gotLastLocation = false;
    manager.requestLocationUpdates(provider, 0, 0, LocationDataCollector.this, Looper.getMainLooper());
    Logger.d(this, "start collecting location data from: " + provider);

    try {
        Logger.d(this, "sleeping: " + time);
        Thread.sleep(time);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    //stop listening for location updates if we are on network. That is done because network location uses network and breaks NetworkCondition
    if (locationType == LocationType.network) {
        manager.removeUpdates(this);
    }
}

From source file:com.guardtrax.ui.screens.SplashScreen.java

private void initialize() {
    if (locationManagerObj == null) {
        locationManagerObj = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

        try {//from ww w. ja  v a 2s. co  m
            gps_enabled = locationManagerObj.isProviderEnabled(LocationManager.GPS_PROVIDER);

            //network_enabled = locationManagerObj.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
        } catch (Exception ex) {
        }
    }

    // don't start listeners if no provider is enabled - Changed to to look for both
    //if (!gps_enabled) 
    if (!gps_enabled && !network_enabled) {
        AlertDialog.Builder dialog = new AlertDialog.Builder(SplashScreen.this);
        dialog.setTitle("Info");
        dialog.setMessage("Please enable GPS!");
        dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                System.exit(0);
            }
        });
        dialog.show();
    } else {
        Runnable showWaitDialog = new Runnable() {
            @Override
            public void run() {
                Looper.prepare();

                int i = 0;

                //if syncComplete is true already it means that we are not trying to sync, hence delay so that splash screen can close slowly
                if (syncComplete) {
                    try {
                        Thread.sleep(1000);
                    } catch (Exception e) {
                    }
                } else {
                    while (!syncComplete || i++ < 10) {
                        try {
                            Thread.sleep(1000);
                        } catch (Exception e) {
                            break;
                        }
                    }

                    //make sure background task is completed.  If not, force it closed
                    if (!syncComplete) {
                        try {
                            if (syncdb.getStatus() != AsyncTask.Status.FINISHED)
                                syncdb.cancel(true);
                        } catch (Exception e) {
                        }
                    }
                }

                //After receiving first GPS Fix dismiss the Progress Dialog
                dialog.dismiss();

                //calling the tab class causes the current tab to be displayed (set to tab(0) which is the HomeScreen)

                Intent intent = new Intent();
                intent.setClass(SplashScreen.this, HomeScreen.class);
                startActivity(intent);

                //transition from splash to main menu is slowed down to a fade by this command
                overridePendingTransition(R.anim.activityfadein, R.anim.splashfadeout);

                SplashScreen.this.finish();
            }
        };

        // Create a Dialog to let the User know that we're waiting for a GPS Fix
        dialog = ProgressDialog.show(SplashScreen.this, "Please wait", "Initializing ...", true);

        Thread t = new Thread(showWaitDialog);
        t.start();
    }
}

From source file:com.vonglasow.michael.satstat.SettingsActivity.java

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

    // Show the Up button in the action bar.
    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

    // Display the fragment as the main content.
    getFragmentManager().beginTransaction().replace(android.R.id.content, new SettingsFragment()).commit();

    mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    // some logic to use the pre-1.7 setting KEY_PREF_UPDATE_WIFI as a
    // fallback if KEY_PREF_UPDATE_NETWORKS is not set
    if (!mSharedPreferences.contains(KEY_PREF_UPDATE_NETWORKS)) {
        Set<String> fallbackUpdateNetworks = new HashSet<String>();
        if (mSharedPreferences.getBoolean(KEY_PREF_UPDATE_WIFI, false)) {
            fallbackUpdateNetworks.add(KEY_PREF_UPDATE_NETWORKS_WIFI);
        }/*from   www.  j a  va 2s.  c om*/
        SharedPreferences.Editor spEditor = mSharedPreferences.edit();
        spEditor.putStringSet(KEY_PREF_UPDATE_NETWORKS, fallbackUpdateNetworks);
        spEditor.commit();
    }

    // by default, show GPS and network location in map
    if (!mSharedPreferences.contains(KEY_PREF_LOC_PROV)) {
        Set<String> defaultLocProvs = new HashSet<String>(
                Arrays.asList(new String[] { LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER }));
        SharedPreferences.Editor spEditor = mSharedPreferences.edit();
        spEditor.putStringSet(KEY_PREF_LOC_PROV, defaultLocProvs);
        spEditor.commit();
    }
}

From source file:com.tagaugmentedreality.utilties.Utilities.java

public static boolean locationProviderStatus(Context context) {
    LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
            && locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
        return true;
    } // end if// w  w  w.j  a v  a 2 s  . c o m
    else if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        return true;
    } // end if
    else if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
        return true;
    } // end else if
    else {
        return false;
    } // end else
}