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.github.tdudziak.gps_lock_lock.LockService.java

private void enable() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    mLockTime = prefs.getInt("lockTime", 5);
    mStartTime = System.currentTimeMillis();
    mNotificationUi.enable(); // setup UI
    requestUiUpdate(); // start broadcasting UI update intents

    // Setup GPS listening.
    mLocationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, GPS_MIN_TIME, 0, this);

    mIsActive = true;/*from  ww w  .j  a v a2s. c  om*/

    Log.i(TAG, "enable()");
}

From source file:com.android.gpstest.GpsTestActivity.java

/** Called when the activity is first created. */
@Override/*from w  ww  . j  av a 2 s  .co  m*/
public void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    super.onCreate(savedInstanceState);
    sInstance = this;

    // Set the default values from the XML file if this is the first
    // execution of the app
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);

    mService = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (ActivityCompat.checkSelfPermission(this,
            android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(this,
                    android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        // Permission Denied
        Toast.makeText(this, getString(R.string.permission_denied), Toast.LENGTH_SHORT).show();
        finish();
        return;
    } else {
        mProvider = mService.getProvider(LocationManager.GPS_PROVIDER);
        if (mProvider == null) {
            Log.e(TAG, "Unable to get GPS_PROVIDER");
            Toast.makeText(this, getString(R.string.gps_not_supported), Toast.LENGTH_SHORT).show();
            finish();
            return;
        }
    }
    mService.addGpsStatusListener(this);

    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);

    // If we have a large screen, show all the fragments in one layout
    if (GpsTestUtil.isLargeScreen(this)) {
        setContentView(R.layout.activity_main_large_screen);
        mIsLargeScreen = true;
    } else {
        setContentView(R.layout.activity_main);
    }

    initActionBar(savedInstanceState);

    SharedPreferences settings = Application.getPrefs();

    double tempMinTime = Double.valueOf(settings.getString(getString(R.string.pref_key_gps_min_time),
            getString(R.string.pref_gps_min_time_default_sec)));
    minTime = (long) (tempMinTime * SECONDS_TO_MILLISECONDS);
    minDistance = Float.valueOf(settings.getString(getString(R.string.pref_key_gps_min_distance),
            getString(R.string.pref_gps_min_distance_default_meters)));

    if (settings.getBoolean(getString(R.string.pref_key_auto_start_gps), true)) {
        gpsStart();
    }
}

From source file:com.example.mohamed.a3qaqer.RegisterActvity.java

private void getloc() {
    if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        loc_string = "none";// indicate that no gps data
        return;/*ww w  .  ja  v a  2  s  . co m*/
    }
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setBearingRequired(true);
    criteria.setCostAllowed(true);
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    criteria.setAltitudeRequired(false);
    String bestProvider = locationManager.getBestProvider(criteria, true);
    if (ActivityCompat.checkSelfPermission(this,
            android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(this,
                    android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        return;
    }
    locationManager.requestLocationUpdates(bestProvider, 2000, 10, new LocationListener() {
        @Override
        public void onStatusChanged(String s, int i, Bundle bundle) {
        }

        @Override
        public void onProviderEnabled(String s) {
        }

        @Override
        public void onProviderDisabled(String s) {
        }

        @Override
        public void onLocationChanged(final Location location) {
        }
    });
    Location myLocation = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
    double longitude = myLocation.getLongitude();
    double latitude = myLocation.getLatitude();
    loc_string = latitude + "-" + longitude;

}

From source file:com.alexandreroman.nrelay.NmeaRelayService.java

@Override
public void onProviderEnabled(String provider) {
    if (LocationManager.GPS_PROVIDER.equals(provider)) {
        Log.i(TAG, "GPS is enabled by user");
        updateState(State.WAITING_FOR_GPS_FIX);
    }/*from  ww  w.ja  v  a2 s  .c  o  m*/
}

From source file:com.nextgis.rehacompdemo.RoutingActivity.java

public static Location snapToLine(Location pointA, Location pointB, Location pointP, boolean clampToSegment) {
    Location projection = new Location(LocationManager.GPS_PROVIDER);

    double ax = pointA.getLatitude();
    double ay = pointA.getLongitude();
    double bx = pointB.getLatitude();
    double by = pointB.getLongitude();

    // no line, locations are similar
    if (ax == bx && ay == by)
        return pointA;

    double px = pointP.getLatitude();
    double py = pointP.getLongitude();

    double apx = px - ax;
    double apy = py - ay;
    double abx = bx - ax;
    double aby = by - ay;

    double ab2 = abx * abx + aby * aby;
    double ap_ab = apx * abx + apy * aby;
    double t = ap_ab / ab2;

    if (clampToSegment) {
        if (t < 0) {
            t = 0;/*from  w  w w.  java2 s  .c om*/
        } else if (t > 1) {
            t = 1;
        }
    }

    projection.setLatitude(ax + abx * t);
    projection.setLongitude(ay + aby * t);

    return projection;
}

From source file:com.example.administrator.myapplication2._5_Group._5_Group.RightFragment.java

/**
 *   ??  ? /* www. j a  v a  2 s .c o  m*/
 */
private void startLocationService() {
    //  ? ? 
    manager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);

    //   ?   ? ?
    gpsListener = new GPSListener();
    long minTime = 5000;//GPS    - 20  
    float minDistance = 1;//?? (10m)

    // GPS   
    manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, minTime, minDistance, gpsListener);

    // ?   
    manager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, minTime, minDistance, gpsListener);

}

From source file:com.alexandreroman.nrelay.NmeaRelayService.java

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
    if (LocationManager.GPS_PROVIDER.equals(provider)) {
        if (LocationProvider.TEMPORARILY_UNAVAILABLE == status) {
            Log.i(TAG, "GPS is temporarily unavailable");
            updateState(State.WAITING_FOR_GPS_FIX);
        }//from w  ww. j  a  va 2s .co  m
    }
}

From source file:com.oonusave.coupon.MyMapStore.java

@Override
protected void onResume() {
    super.onResume();
    DataUtil.CURRENT_SCREEN = PageManager.STORES_MAP_SCREEN;
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 500, 10, finder);
    setUpMapIfNeeded();//from   w w w.jav  a2s .com
}

From source file:com.stfalcon.hromadskyipatrol.ui.activity.MainActivity.java

private boolean checkLocationManager() {
    if (!((LocationManager) getSystemService(Context.LOCATION_SERVICE))
            .isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        if (!isGPSDialogShowed) {
            LocationDialog.showSettingsAlert(this);
            isGPSDialogShowed = true;//from ww w.j a v a2s  .c  o m
        }
        return false;
    }
    return true;
}

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  ww  . j  av a  2 s  . c o m
    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();
}