List of usage examples for android.location LocationManager GPS_PROVIDER
String GPS_PROVIDER
To view the source code for android.location LocationManager GPS_PROVIDER.
Click Source Link
From source file:fr.louisbl.cordova.locationservices.CordovaLocationServices.java
private boolean isGPSdisabled() { LocationManager lm = null;/* w ww . j ava 2s . c om*/ boolean gps_enabled; if (lm == null) lm = (LocationManager) this.cordova.getActivity().getSystemService(Context.LOCATION_SERVICE); try { gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER); } catch (Exception ex) { ex.printStackTrace(); gps_enabled = false; } return !gps_enabled; }
From source file:ca.ualberta.cs.cmput301w15t04team04project.FragmentEditClaim2.java
public void getClaimLocation(View view) { LocationManager lm = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, listener); }
From source file:com.google.transporttracker.TrackerActivity.java
/** * Third and final validation check - ensures GPS is enabled, and if not, prompts to * enable it, otherwise all checks pass so start the location tracking service. *///from w w w . j a v a 2s .com private void checkGpsEnabled() { LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE); if (!lm.isProviderEnabled(LocationManager.GPS_PROVIDER)) { reportGpsError(); } else { resolveGpsError(); startLocationService(); } }
From source file:com.vrjco.v.demo.MainActivity.java
private void setTestCoordinate() { //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;/*w ww . j av a 2 s .c o m*/ } lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 1000 * 60, testLocationListener); lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 1000 * 60, testLocationListener); 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) { test_lat = location.getLatitude(); test_longi = location.getLongitude(); tvtestlat.setText(Double.toString(test_lat)); tvtestlongi.setText(Double.toString(test_longi)); test_is_set = true; } } else { Toast.makeText(this, "LOCATION PROVIDER NOT AVAILABLE", Toast.LENGTH_LONG).show(); test_is_set = false; } lm.removeUpdates(testLocationListener); }
From source file:com.jesjimher.bicipalma.MesProperesActivity.java
/** * Activa la bsqueda de ubicacin usando el mejor mtodo disponible *///ww w . j a v a 2s . c o m private void activarUbicacion() { locationManager.removeUpdates(this); // Comprobar si se ha activado o no el GPS, y decidir el mtodo para ubicarse if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) mUbic = LocationManager.GPS_PROVIDER; else { // Toast.makeText(getApplicationContext(), R.string.avisonogps, Toast.LENGTH_LONG).show(); mUbic = providerCoarse; } locationManager.requestLocationUpdates(mUbic, 10, 0, (LocationListener) this); }
From source file:io.kristal.locationplugin.LocationPlugin.java
/*********************************************************************************************** * * METHODS/* www. j a v a2s .com*/ * **********************************************************************************************/ private void getActiveProviders(Context context) { mProviders = new ArrayList<>(); mLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); if (mLocationManager.isProviderEnabled(LocationManager.PASSIVE_PROVIDER)) { mProviders.add(LocationManager.PASSIVE_PROVIDER); } if (mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { mProviders.add(LocationManager.NETWORK_PROVIDER); } if (mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { mProviders.add(LocationManager.GPS_PROVIDER); } }
From source file:com.company.millenium.iwannask.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //GPS//from w w w .j a v a2 s . c om locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); locationListener = new LocationListener() { public void onLocationChanged(Location location) { if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // Check Permissions Now final int REQUEST_LOCATION = 2; if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION)) { // Display UI and wait for user interaction } else { ActivityCompat.requestPermissions(MainActivity.this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, REQUEST_LOCATION); } } else { locationManager.removeUpdates(this); } } public void onStatusChanged(String string, int integer, Bundle bundle) { } public void onProviderEnabled(String string) { } public void onProviderDisabled(String string) { } }; if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // Check Permissions Now final int REQUEST_LOCATION = 2; if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_FINE_LOCATION)) { // Display UI and wait for user interaction } else { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, REQUEST_LOCATION); } } else { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1000, locationListener); } int delay = 30000; // delay for 30 sec. int period = 3000000; // repeat every 5.3min. Timer timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { public void run() { if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // Check Permissions Now final int REQUEST_LOCATION = 2; if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION)) { // Display UI and wait for user interaction } else { ActivityCompat.requestPermissions(MainActivity.this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, REQUEST_LOCATION); } } else { locationManager.removeUpdates(locationListener); } } }, delay, period); getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); Intent mIntent = getIntent(); URL = Constants.SERVER_URL; if (mIntent.hasExtra("url")) { myWebView = null; startActivity(getIntent()); String url = mIntent.getStringExtra("url"); URL = Constants.SERVER_URL + url; } CookieSyncManager.createInstance(this); CookieSyncManager.getInstance().startSync(); myWebView = (WebView) findViewById(R.id.webview); myWebView.getSettings().setGeolocationDatabasePath(this.getFilesDir().getPath()); myWebView.getSettings().setGeolocationEnabled(true); WebSettings webSettings = myWebView.getSettings(); webSettings.setUseWideViewPort(false); if (!DetectConnection.checkInternetConnection(this)) { webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); showNoConnectionDialog(this); } else { webSettings.setCacheMode(WebSettings.LOAD_DEFAULT); } webSettings.setJavaScriptEnabled(true); myWebView.addJavascriptInterface(new webappinterface(this), "android"); webSettings.setLoadWithOverviewMode(true); webSettings.setUseWideViewPort(true); myWebView.setOverScrollMode(View.OVER_SCROLL_NEVER); //location test webSettings.setAppCacheEnabled(true); webSettings.setDatabaseEnabled(true); webSettings.setDomStorageEnabled(true); myWebView.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { CookieSyncManager.getInstance().sync(); } @Override public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { handler.proceed(); // Ignore SSL certificate errors } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (Uri.parse(url).getHost().equals(Constants.HOST) || Uri.parse(url).getHost().equals(Constants.WWWHOST)) { // This is my web site, so do not override; let my WebView load // the page return false; } // Otherwise, the link is not for a page on my site, so launch // another Activity that handles URLs Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(intent); return true; } }); myWebView.setWebChromeClient(new WebChromeClient() { public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) { callback.invoke(origin, true, false); } @Override public void onPermissionRequest(final PermissionRequest request) { Log.d(TAG, "onPermissionRequest"); runOnUiThread(new Runnable() { @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public void run() { if (request.getOrigin().toString().equals("https://apprtc-m.appspot.com/")) { request.grant(request.getResources()); } else { request.deny(); } } }); } public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) { // Double check that we don't have any existing callbacks if (mFilePathCallback != null) { mFilePathCallback.onReceiveValue(null); } mFilePathCallback = filePathCallback; // Set up the take picture intent Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(getPackageManager()) != null) { // Create the File where the photo should go File photoFile = null; try { photoFile = createImageFile(); takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath); } catch (IOException ex) { // Error occurred while creating the File Log.e(TAG, "Unable to create Image File", ex); } // Continue only if the File was successfully created if (photoFile != null) { mCameraPhotoPath = "file:" + photoFile.getAbsolutePath(); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); } else { takePictureIntent = null; } } // Set up the intent to get an existing image Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT); contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE); contentSelectionIntent.setType("image/*"); // Set up the intents for the Intent chooser Intent[] intentArray; if (takePictureIntent != null) { intentArray = new Intent[] { takePictureIntent }; } else { intentArray = new Intent[0]; } Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER); chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent); chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser"); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray); startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE); return true; } }); // setContentView(myWebView); // myWebView.loadUrl(URL); myWebView.loadUrl(URL); mRegistrationBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { // mRegistrationProgressBar.setVisibility(ProgressBar.GONE); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); boolean sentToken = sharedPreferences.getBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false); } }; //CookieManager mCookieManager = CookieManager.getInstance(); //Boolean hasCookies = mCookieManager.hasCookies(); //while(!hasCookies); if (checkPlayServices()) { // Start IntentService to register this application with GCM. Intent intent = new Intent(this, RegistrationIntentService.class); //intent.putExtra("session", session); startService(intent); } Boolean isFirstRun = getSharedPreferences("PREFERENCE", MODE_PRIVATE).getBoolean("isFirstRun", true); if (isFirstRun) { //show start activity startActivity(new Intent(MainActivity.this, MyIntro.class)); } //if (!isOnline()) // showNoConnectionDialog(this); getSharedPreferences("PREFERENCE", MODE_PRIVATE).edit().putBoolean("isFirstRun", false).commit(); //Pull-to-refresh mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.container); mSwipeRefreshLayout.setOnRefreshListener(this); }
From source file:ca.rmen.android.networkmonitor.app.prefs.PreferenceFragmentActivity.java
/** * Checks if we have either the GPS or Network location provider enabled. If not, shows a popup dialog telling the user they should go to the system * settings to enable location tracking. *//* w w w .j a va 2 s . co m*/ private void checkLocationSettings() { // If the user chose high accuracy, make sure we have at least one location provider. LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (!(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) || locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))) { DialogFragmentFactory.showConfirmDialog(this, getString(R.string.no_location_confirm_dialog_title), getString(R.string.no_location_confirm_dialog_message), ID_ACTION_LOCATION_SETTINGS, null); } else { finish(); } }
From source file:com.uproot.trackme.LocationActivity.java
private void setup() { Location gpsLocation = null;/* ww w. jav a2s. com*/ Location networkLocation = null; mLocationManager.removeUpdates(listener); mLatLng.setText(R.string.unknown); mAddress.setText(R.string.unknown); // Get fine location updates only. if (mUseFine) { // Request updates from just the fine (gps) provider. gpsLocation = requestUpdatesFromProvider(LocationManager.GPS_PROVIDER, R.string.not_support_gps); // Update the UI immediately if a location is obtained. if (gpsLocation != null) updateUILocation(gpsLocation); } else if (mUseBoth) { // Get coarse and fine location updates. // Request updates from both fine (gps) and coarse (network) // providers. gpsLocation = requestUpdatesFromProvider(LocationManager.GPS_PROVIDER, R.string.not_support_gps); networkLocation = requestUpdatesFromProvider(LocationManager.NETWORK_PROVIDER, R.string.not_support_network); // If both providers return last known locations, compare the two // and use the better // one to update the UI. If only one provider returns a location, // use it. if (gpsLocation != null && networkLocation != null) { updateUILocation(getBetterLocation(gpsLocation, networkLocation)); } else if (gpsLocation != null) { updateUILocation(gpsLocation); } else if (networkLocation != null) { updateUILocation(networkLocation); } } }
From source file:com.alexandreroman.nrelay.NmeaRelayService.java
@Override public void onProviderDisabled(String provider) { if (LocationManager.GPS_PROVIDER.equals(provider)) { Log.i(TAG, "GPS is disabled by user"); updateState(State.GPS_DISABLED); }//www. j a v a2s . c o m }