Example usage for android.location LocationManager isProviderEnabled

List of usage examples for android.location LocationManager isProviderEnabled

Introduction

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

Prototype

public boolean isProviderEnabled(String provider) 

Source Link

Document

Returns the current enabled/disabled status of the given provider.

Usage

From source file:wanthavers.mad.cs.fau.de.wanthavers_android.desirelist.DesireListFragment.java

private boolean isGpsEnabled() {
    LocationManager locManager = (LocationManager) getActivity()
            .getSystemService(getActivity().LOCATION_SERVICE);
    return locManager.isProviderEnabled(LocationManager.GPS_PROVIDER);

}

From source file:gov.nasa.arc.geocam.geocam.GeoCamMobile.java

@Override
public void onResume() {
    super.onResume();
    Log.d(DEBUG_ID, "GeoCamMobile::onResume called");

    mForeground.foreground();/*from   ww  w.  ja  v  a 2 s . c o  m*/

    mServiceBound = bindService(new Intent(this, GeoCamService.class), mServiceConn, Context.BIND_AUTO_CREATE);
    if (!mServiceBound) {
        Log.e(DEBUG_ID, "GeoCamMobile::onResume - error binding to service");
    }

    IntentFilter filter = new IntentFilter(GeoCamMobile.LOCATION_CHANGED);
    this.registerReceiver(mLocationReceiver, filter);

    LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        showDialog(DIALOG_GPS_OFF_ID);
    }
}

From source file:org.nasa.openspace.gc.geolocation.LocationActivity.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()
        new EnableGpsDialogFragment().show(getSupportFragmentManager(), "enableGpsDialog");
    }//from  w w  w . j  a  v  a  2s.  c om
}

From source file:com.example.scrumptious.PickerActivity.java

@Override
protected void onStart() {
    super.onStart();
    if (FRIEND_PICKER.equals(getIntent().getData())) {
        try {//from   ww w. j  a  va2 s. c om
            friendPickerFragment.loadData(false);
        } catch (Exception ex) {
            onError(ex);
        }
    } else if (PLACE_PICKER.equals(getIntent().getData())) {
        try {
            Location location = null;
            Criteria criteria = new Criteria();
            LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            String bestProvider = locationManager.getBestProvider(criteria, false);
            if (bestProvider != null) {
                location = locationManager.getLastKnownLocation(bestProvider);
                if (locationManager.isProviderEnabled(bestProvider) && locationListener == null) {
                    locationListener = new LocationListener() {
                        @Override
                        public void onLocationChanged(Location location) {
                            boolean updateLocation = true;
                            Location prevLocation = placePickerFragment.getLocation();
                            if (prevLocation != null) {
                                updateLocation = location.distanceTo(prevLocation) >= LOCATION_CHANGE_THRESHOLD;
                            }
                            if (updateLocation) {
                                placePickerFragment.setLocation(location);
                                placePickerFragment.loadData(true);
                            }
                        }

                        @Override
                        public void onStatusChanged(String s, int i, Bundle bundle) {
                        }

                        @Override
                        public void onProviderEnabled(String s) {
                        }

                        @Override
                        public void onProviderDisabled(String s) {
                        }
                    };
                    locationManager.requestLocationUpdates(bestProvider, 1, LOCATION_CHANGE_THRESHOLD,
                            locationListener, Looper.getMainLooper());
                }
            }
            if (location != null) {
                placePickerFragment.setLocation(location);
                placePickerFragment.setRadiusInMeters(SEARCH_RADIUS_METERS);
                placePickerFragment.setSearchText(SEARCH_TEXT);
                placePickerFragment.setResultsLimit(SEARCH_RESULT_LIMIT);
                placePickerFragment.loadData(false);
            }
        } catch (Exception ex) {
            onError(ex);
        }
    }
}

From source file:es.rgmf.libresportgps.MainActivity.java

/**
 * Check if GPS is enabled. If GPS is not enabled then It shows an Dialog
 * through the user can enabled it.//  w  w w.  ja v a2 s  .co m
 */
private void checkGpsProvider() {
    LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE);
    if (!lm.isProviderEnabled(LocationManager.GPS_PROVIDER) && !Session.isAlertDialogGPSShowed()) {
        Session.setAlertDialogGPSShowed(true);
        new AlertDialog.Builder(this).setTitle(R.string.gps_disabled)
                .setIcon(android.R.drawable.ic_dialog_alert)
                .setMessage(getResources().getString(R.string.gps_disabled_hint)).setCancelable(true)
                .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                    }
                }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                }).create().show();
    }
}

From source file:jp.co.tweetmap.MainActivity.java

/**
 * Check GPS is confirmed valid, and displays an alert dialog If it is not valid.
 */// w ww  .  j  a  v a 2 s .  co m
private void checkGpsService() {
    LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    if (null == locationManager || !locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {

        // If check box is checked, return here.
        final SharedPreferences sharePref = PreferenceManager
                .getDefaultSharedPreferences(getApplicationContext());
        boolean isHide = sharePref.getBoolean(GPS_DLG_DISPLAY, false);
        if (isHide) {
            return;
        }

        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);

        LayoutInflater factory = LayoutInflater.from(this);
        final View inputView = factory.inflate(R.layout.dialog_gps_alert, null);

        CheckBox checkbox = (CheckBox) inputView.findViewById(R.id.dialog_checkbox);
        checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                isState = isChecked;
            }
        });

        alertDialogBuilder.setView(inputView).setPositiveButton(
                getResources().getString(R.string.gps_alert_yes_button), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        Intent callGPSSettingIntent = new Intent(
                                android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                        startActivity(callGPSSettingIntent);
                        dialog.dismiss();
                    }
                }).setNegativeButton(getResources().getString(R.string.gps_alert_no_button),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                sharePref.edit().putBoolean(GPS_DLG_DISPLAY, isState).apply();
                                dialog.cancel();
                            }
                        });

        alertDialogBuilder.setTitle(getResources().getString(R.string.gps_alert_dlg_title));
        alertDialogBuilder.setMessage(getResources().getString(R.string.gps_alert_dlg_body));
        alertDialogBuilder.setCancelable(false);
        alertDialogBuilder.create();
        alertDialogBuilder.show();
    }
}

From source file:activities.GatewayActivity.java

@Override
public void locationMode(boolean on) {
    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    boolean gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    boolean networkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
    if (on) {/*from  w  ww  . ja va2  s.  c  o m*/
        if (!gpsEnabled || !networkEnabled) {
            new LocationDialog().show(getSupportFragmentManager(), "locationdialog");
            configFragment.updateLocationView(false);
            sApp.isLocationOn = false;
        } else {
            if (!sApp.locationService.isRunning())
                sApp.locationService.start();
            sApp.isLocationOn = true;
            showToast(getString(R.string.location_enabled));
        }
    } else {
        if (sApp.locationService.isRunning())
            sApp.locationService.stop();
        showToast(getString(R.string.toast_stopped_location_service));
        sApp.isLocationOn = false;
    }
    configFragment.updateLocationView(sApp.isLocationOn);
}

From source file:com.example.snapcacheexample.PickerActivity.java

@Override
protected void onStart() {
    super.onStart();
    if (FRIEND_PICKER.equals(getIntent().getData())) {
        try {/*from  w  w w .  j ava2 s  . co m*/
            friendPickerFragment.loadData(false);
        } catch (Exception ex) {
            onError(ex);
        }
    } else if (PLACE_PICKER.equals(getIntent().getData())) {
        try {
            Location location = null;
            Criteria criteria = new Criteria();
            LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            String bestProvider = locationManager.getBestProvider(criteria, false);
            if (bestProvider != null) {
                location = locationManager.getLastKnownLocation(bestProvider);
                if (locationManager.isProviderEnabled(bestProvider) && locationListener == null) {
                    locationListener = new LocationListener() {
                        @Override
                        public void onLocationChanged(Location location) {
                            float distance = location.distanceTo(placePickerFragment.getLocation());
                            if (distance >= LOCATION_CHANGE_THRESHOLD) {
                                placePickerFragment.setLocation(location);
                                placePickerFragment.loadData(true);
                            }
                        }

                        @Override
                        public void onStatusChanged(String s, int i, Bundle bundle) {
                        }

                        @Override
                        public void onProviderEnabled(String s) {
                        }

                        @Override
                        public void onProviderDisabled(String s) {
                        }
                    };
                    locationManager.requestLocationUpdates(bestProvider, 1, LOCATION_CHANGE_THRESHOLD,
                            locationListener, Looper.getMainLooper());
                }
            }
            if (location == null) {
                String model = Build.MODEL;
                if (model.equals("sdk") || model.equals("google_sdk") || model.contains("x86")) {
                    // this may be the emulator, pretend we're in an exotic place
                    location = SAN_FRANCISCO_LOCATION;
                }
            }
            if (location != null) {
                placePickerFragment.setLocation(location);
                placePickerFragment.setRadiusInMeters(SEARCH_RADIUS_METERS);
                placePickerFragment.setSearchText(SEARCH_TEXT);
                placePickerFragment.setResultsLimit(SEARCH_RESULT_LIMIT);
                placePickerFragment.loadData(false);
            } else {
                onError(getResources().getString(R.string.no_location_error), true);
            }
        } catch (Exception ex) {
            onError(ex);
        }
    }
}

From source file:com.elekso.potfix.MainActivity.java

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

    PowerManager pm = (PowerManager) getApplicationContext()
            .getSystemService(getApplicationContext().POWER_SERVICE);
    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, " POTFIX holding wake lock");
    wl.acquire();/*from   w  w  w  . ja va 2 s. c  om*/
    Globals.getInstance().setFlexiblemap(true);

    //
    //
    //        new Thread(new Runnable(){
    //            @Override
    //            public void run() {
    //                try {
    //                    LALpotfixservicePortBinding service = new LALpotfixservicePortBinding();
    //                    try {
    //                        globaldata_test=service.CheckWS("mandar");
    //
    //                    } catch (Exception e) {
    //                        e.printStackTrace();
    //                    }
    //                } catch (Exception ex) {
    //                    ex.printStackTrace();
    //                }
    //            }
    //        }).start();

    String login = "";

    //  Config.getInstance(getBaseContext(),getCacheDir()).setProfile("df","asd");
    login = Config.getInstance(getBaseContext(), getCacheDir()).getProfileName();
    if (login == null || login.isEmpty()) {
        Intent intent = new Intent(this, LoginActivity.class);
        startActivity(intent);
        return;
    }
    //remove
    //  Stetho.initializeWithDefaults(this);

    // Toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    // Drawer
    drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    tusername = (TextView) drawer.findViewById(R.id.tvusername);
    //        tuseremail =(TextView) findViewById(R.id.tvuseremail);
    //
    //        if(login!=null)
    //            tusername.setText("jhjhjhjh");
    //   if(Config.getInstance().getProfileEmail()!=null)
    //tuseremail.setText(Config.getInstance().getProfileEmail());

    // FAB
    fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setRippleColor(Color.parseColor("#78D6F3"));
    fab.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#039FDC")));
    fab.setImageResource(R.drawable.ic_gps_fixed_white_24dp);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switch (currentFragment) {
            case 1: //profile
                Snackbar.make(view, "Updating Information", Snackbar.LENGTH_LONG).setAction("Action", null)
                        .show();
                Fragment frg = new ProfileFragment();
                FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
                transaction.replace(R.id.frame_containerone, frg);
                transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
                transaction.commit();
                break;
            case 2: //map

                if (Globals.getInstance().getFlexiblemap()) {
                    Snackbar.make(view, "Free to Scroll", Snackbar.LENGTH_LONG).setAction("Action", null)
                            .show();
                    Globals.getInstance().setFlexiblemap(false);
                    fab.setRippleColor(Color.parseColor("#FFE082"));
                    fab.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#FFB300")));
                    fab.setImageResource(R.drawable.ic_gps_off_white_24dp);
                } else {
                    Snackbar.make(view, "Follow Potfix", Snackbar.LENGTH_LONG).setAction("Action", null).show();
                    Globals.getInstance().setFlexiblemap(true);
                    fab.setRippleColor(Color.parseColor("#78D6F3"));
                    fab.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#039FDC")));
                    fab.setImageResource(R.drawable.ic_gps_fixed_white_24dp);
                }
                break;
            case 3: //share
                //Snackbar.make(view, "Some sharing action", Snackbar.LENGTH_LONG).setAction("Action", null).show();
                String[] TO = { "aziz@potfix.com" };
                String[] CC = { "" };
                Intent emailIntent = new Intent(Intent.ACTION_SEND);

                emailIntent.setData(Uri.parse("mailto:"));
                emailIntent.setType("text/plain");
                emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
                emailIntent.putExtra(Intent.EXTRA_CC, CC);
                emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Potfix Communication");
                emailIntent.putExtra(Intent.EXTRA_TEXT, "Email message...");

                try {
                    startActivity(Intent.createChooser(emailIntent, "Send mail..."));
                    finish();
                } catch (android.content.ActivityNotFoundException ex) {
                    Toast.makeText(MainActivity.this, "There is no email client installed.", Toast.LENGTH_SHORT)
                            .show();
                }
                break;
            case 4: //legal
                Snackbar.make(view, "Software License", Snackbar.LENGTH_LONG).setAction("Action", null).show();
                drawer.openDrawer(Gravity.LEFT);
                break;
            }

        }
    });

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    startService(new Intent(getBaseContext(), BackgroundService.class));

    FragmentTransaction mTransaction = getSupportFragmentManager().beginTransaction();
    MapsFragment mFRaFragment = new MapsFragment();
    mTransaction.add(R.id.frame_containerone, mFRaFragment);
    mTransaction.commit();

    LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

    if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        Toast.makeText(this, "GPS is Enabled in your devide", Toast.LENGTH_SHORT).show();
    } else {
        showGPSDisabledAlertToUser();
    }

    //        if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)){
    //            Toast.makeText(this, "Network is Enabled in your devide", Toast.LENGTH_SHORT).show();
    //        }else{
    //            showNetDisabledAlertToUser();
    //        }
    createNotification();
}

From source file:com.example.david.wheretogo_test1.PickerActivity.java

@Override
protected void onStart() {
    super.onStart();
    if (FRIEND_PICKER.equals(getIntent().getData())) {
        try {//from  w  ww  .  j  a  v a  2 s  .  com
            friendPickerFragment.loadData(false);
        } catch (Exception ex) {
            onError(ex);
        }
    } else if (PLACE_PICKER.equals(getIntent().getData())) {
        try {
            Location location = null;
            Criteria criteria = new Criteria();
            LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            String bestProvider = locationManager.getBestProvider(criteria, false);
            if (bestProvider != null) {
                location = locationManager.getLastKnownLocation(bestProvider);
                if (locationManager.isProviderEnabled(bestProvider) && locationListener == null) {
                    locationListener = new LocationListener() {
                        @Override
                        public void onLocationChanged(Location location) {
                            boolean updateLocation = true;
                            Location prevLocation = placePickerFragment.getLocation();
                            if (prevLocation != null) {
                                updateLocation = location.distanceTo(prevLocation) >= LOCATION_CHANGE_THRESHOLD;
                            }
                            if (updateLocation) {
                                placePickerFragment.setLocation(location);
                                placePickerFragment.loadData(true);
                            }
                        }

                        @Override
                        public void onStatusChanged(String s, int i, Bundle bundle) {
                        }

                        @Override
                        public void onProviderEnabled(String s) {
                        }

                        @Override
                        public void onProviderDisabled(String s) {
                        }
                    };
                    locationManager.requestLocationUpdates(bestProvider, 1, LOCATION_CHANGE_THRESHOLD,
                            locationListener, Looper.getMainLooper());
                }
            }
            if (location == null) {
                String model = Build.MODEL;
                if (model.equals("sdk") || model.equals("google_sdk") || model.contains("x86")) {
                    // this may be the emulator, pretend we're in an exotic place
                    location = SAN_FRANCISCO_LOCATION;
                }
            }
            if (location != null) {
                placePickerFragment.setLocation(location);
                placePickerFragment.setRadiusInMeters(SEARCH_RADIUS_METERS);
                placePickerFragment.setSearchText(SEARCH_TEXT);
                placePickerFragment.setResultsLimit(SEARCH_RESULT_LIMIT);
                placePickerFragment.loadData(false);
            } else {
                onError(getResources().getString(R.string.no_location_error), true);
            }
        } catch (Exception ex) {
            onError(ex);
        }
    }
}