Example usage for android.location LocationManager requestLocationUpdates

List of usage examples for android.location LocationManager requestLocationUpdates

Introduction

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

Prototype

@UnsupportedAppUsage
    private void requestLocationUpdates(LocationRequest request, LocationListener listener, Looper looper,
            PendingIntent intent) 

Source Link

Usage

From source file:ca.ualberta.cs.cmput301w15t04team04project.MainActivity.java

/**
 * Called to do initial creation of a fragment.<br>
 * This is called after onAttach(Activity) and before
 * onCreateView(LayoutInflater, ViewGroup, Bundle).<br>
 * Note that this can be called while the fragment's activity is still in
 * the process of being created.<br>
 * As such, you can not rely on things like the activity's content view
 * hierarchy being initialized at this point.<br>
 * If you want to do work once the activity itself is created, see
 * onActivityCreated(Bundle).<br>//from   w w  w  .  j  av a  2 s  .  com
 * 
 * @param savedInstanceState
 *            If the fragment is being re-created from a previous saved
 *            state, this is the state.
 */
/*
 * (non-Javadoc)
 * 
 * @see android.support.v4.app.FragmentActivity#onCreate(android.os.Bundle)
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // searchClaim.setVisible(true);
    setContentView(R.layout.activity_main);
    checker = new NetworkAvailabliltyCheck(getApplicationContext());
    user = SignInManager.loadFromFile(this);
    actionBar = getActionBar();
    actionBar.setTitle("My Local Claims");

    LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    if (checker.getNetworkAvailable()) {
        Toast.makeText(this, "net", Toast.LENGTH_SHORT).show();
        ClaimList claimList = MyLocalClaimListManager.loadClaimList(getApplicationContext(), user.getName());
        localController = new MyLocalClaimListController(claimList);
        localController.upload(getApplicationContext());
    }
    /*
     * if (location != null){ user.setHomelocation(location); TextView tv =
     * (TextView) findViewById(R.id.gpsHomeLocationTextView);
     * tv.setText("Lat: " + location.getLatitude() + "\nLong: " +
     * location.getLongitude()); }
     */
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, listener);

    initialisePaging();
}

From source file:com.swetha.easypark.GetParkingLots.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    if (!isGooglePlayServicesAvailable()) {
        finish();// ww  w. ja  v  a  2s .  c  o  m
    }
    super.onCreate(savedInstanceState);
    setContentView(R.layout.getparkinglots);

    SupportMapFragment supportMapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    googleMap = supportMapFragment.getMap();

    googleMap.setMyLocationEnabled(true);
    LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    gps_enabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    network_enabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

    if (gps_enabled) {
        Criteria criteria = new Criteria();

        provider = locationManager.getBestProvider(criteria, true);

        if (provider != null && !provider.equals("")) {

            locationManager.requestLocationUpdates(provider, 500, 1, GetParkingLots.this);
            // Get the location from the given provider 
            location = locationManager.getLastKnownLocation(provider);

        }
    }
    Log.i("GetParkingLots", "Value of network_enabled and location" + network_enabled + location);
    if (location == null && network_enabled) {

        location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 500, 1, GetParkingLots.this);

    }

    if (location == null && !network_enabled && !gps_enabled) {
        Toast.makeText(getBaseContext(), "Enable your location services", Toast.LENGTH_LONG).show();
    }
    if (location != null)
        onLocationChanged(location);
    else {

        Toast.makeText(getBaseContext(), "Location can't be retrieved", Toast.LENGTH_SHORT).show();
    }

    tv_fromTime = (TextView) findViewById(R.id.tv_fromTime);
    fromTimeString = Constants.dtf.format(new Date()).toString();
    tv_fromTime.setText(fromTimeString);
    long lval = DateTimeHelpers.convertToLongFromTime(Constants.dtf.format(new Date()).toString());
    Log.i("GetParkingLots",
            "The value of current time:" + Constants.dtf.format(new Date()).toString() + "in long is" + lval);
    Log.i("GetParkingLots",
            "The value of current time:" + lval + "in long is" + DateTimeHelpers.convertToTimeFromLong(lval));
    tv_toTime = (TextView) findViewById(R.id.tv_ToTime);
    // Parsing the date
    toTimeString = Constants.dtf.format(new Date()).toString();
    tv_toTime.setText(toTimeString);

    btnFromTime = (Button) findViewById(R.id.fromButton);
    btnFromTime.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {

            // Create the dialog
            final Dialog mDateTimeDialog = new Dialog(GetParkingLots.this);
            // Inflate the root layout
            final RelativeLayout mDateTimeDialogView = (RelativeLayout) getLayoutInflater()
                    .inflate(R.layout.date_time_dialog, null);
            // Grab widget instance
            mDateTimePicker = (DateTimePicker) mDateTimeDialogView.findViewById(R.id.DateTimePicker);
            mDateTimePicker.setDateChangedListener(GetParkingLots.this);

            // Update demo TextViews when the "OK" button is clicked 
            ((Button) mDateTimeDialogView.findViewById(R.id.SetDateTime))
                    .setOnClickListener(new OnClickListener() {
                        Calendar cal;

                        @SuppressWarnings("deprecation")
                        public void onClick(View v) {
                            mDateTimePicker.clearFocus();
                            try {
                                cal = new GregorianCalendar(mDateTimePicker.getYear(),
                                        Integer.parseInt(mDateTimePicker.getMonth()), mDateTimePicker.getDay(),
                                        mDateTimePicker.getHour(), mDateTimePicker.getMinute());
                                fromTimeString = DateTimeHelpers.dtf.format(cal.getTime());
                                tv_fromTime.setText(fromTimeString);
                            } catch (Exception e) {
                                final AlertDialog alertDialog = new AlertDialog.Builder(GetParkingLots.this)
                                        .create();

                                alertDialog.setMessage("Enter a valid date");

                                alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int which) {

                                        alertDialog.dismiss();
                                    }
                                });

                                alertDialog.show();
                            }

                            mDateTimeDialog.dismiss();
                        }
                    });

            // Cancel the dialog when the "Cancel" button is clicked
            ((Button) mDateTimeDialogView.findViewById(R.id.CancelDialog))
                    .setOnClickListener(new OnClickListener() {

                        public void onClick(View v) {
                            // TODO Auto-generated method stub
                            mDateTimeDialog.cancel();
                        }
                    });

            // Reset Date and Time pickers when the "Reset" button is clicked

            ((Button) mDateTimeDialogView.findViewById(R.id.ResetDateTime))
                    .setOnClickListener(new OnClickListener() {

                        public void onClick(View v) {
                            // TODO Auto-generated method stub
                            mDateTimePicker.reset();
                        }
                    });

            // Setup TimePicker
            // No title on the dialog window
            mDateTimeDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            // Set the dialog content view
            mDateTimeDialog.setContentView(mDateTimeDialogView);
            // Display the dialog
            mDateTimeDialog.show();

        }
    });

    btnToTime = (Button) findViewById(R.id.toButton);
    btnToTime.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {

            // Create the dialog
            final Dialog mDateTimeDialog = new Dialog(GetParkingLots.this);
            // Inflate the root layout
            final RelativeLayout mDateTimeDialogView = (RelativeLayout) getLayoutInflater()
                    .inflate(R.layout.date_time_dialog, null);
            // Grab widget instance
            final DateTimePicker mDateTimePicker = (DateTimePicker) mDateTimeDialogView
                    .findViewById(R.id.DateTimePicker);
            mDateTimePicker.setDateChangedListener(GetParkingLots.this);

            // Update demo TextViews when the "OK" button is clicked 
            ((Button) mDateTimeDialogView.findViewById(R.id.SetDateTime))
                    .setOnClickListener(new OnClickListener() {
                        Calendar cal;

                        @SuppressWarnings("deprecation")
                        public void onClick(View v) {
                            mDateTimePicker.clearFocus();

                            Log.i("toButton", "Value of ToString before cal" + toTimeString);
                            try {
                                cal = new GregorianCalendar(mDateTimePicker.getYear(),
                                        Integer.parseInt(mDateTimePicker.getMonth()), mDateTimePicker.getDay(),
                                        mDateTimePicker.getHour(), mDateTimePicker.getMinute());
                                toTimeString = DateTimeHelpers.dtf.format(cal.getTime());
                                Log.i("toButton", "Value of ToString before cal" + toTimeString);

                                tv_toTime.setText(toTimeString);

                            } catch (Exception e) // fixing the bug where the user doesnt enter anything in the textbox
                            {
                                final AlertDialog alertDialog = new AlertDialog.Builder(GetParkingLots.this)
                                        .create();

                                alertDialog.setMessage("Enter a valid date");
                                alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int which) {
                                        alertDialog.dismiss();
                                    }
                                });

                                alertDialog.show();
                            }
                            //dateTimeTo = new DateTime(mDateTimePicker.getYear(), Integer.parseInt(mDateTimePicker.getMonth()) ,  mDateTimePicker.getDay(),  mDateTimePicker.getHour(),  mDateTimePicker.getMinute()); ;

                            mDateTimeDialog.dismiss();
                        }
                    });

            ((Button) mDateTimeDialogView.findViewById(R.id.CancelDialog))
                    .setOnClickListener(new OnClickListener() {

                        public void onClick(View v) {
                            // TODO Auto-generated method stub
                            mDateTimeDialog.cancel();
                        }
                    });

            // Reset Date and Time pickers when the "Reset" button is clicked

            ((Button) mDateTimeDialogView.findViewById(R.id.ResetDateTime))
                    .setOnClickListener(new OnClickListener() {

                        public void onClick(View v) {
                            // TODO Auto-generated method stub
                            mDateTimePicker.reset();
                        }
                    });

            // Setup TimePicker
            // No title on the dialog window
            mDateTimeDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            // Set the dialog content view
            mDateTimeDialog.setContentView(mDateTimeDialogView);
            // Display the dialog
            mDateTimeDialog.show();

        }
    });

    btnGetParkingLots = (Button) findViewById(R.id.getNearByParkingLotsButton);
    btnGetParkingLots.setOnClickListener(new View.OnClickListener() {

        @SuppressWarnings("deprecation")
        public void onClick(View v) {
            et_search = (EditText) findViewById(R.id.edittextsearch);
            rg = (RadioGroup) findViewById(R.id.rg);
            checkedRbId = rg.getCheckedRadioButtonId();
            Log.i("LOG_TAG: GetParkingLots", "checked radiobutton id is" + checkedRbId);

            if (checkedRbId == R.id.rbradius) {
                isRadiusIndicator = true;
                radius = et_search.getText().toString();
            } else {
                isRadiusIndicator = false;
                zipcode = et_search.getText().toString();
            }

            final Intent intent = new Intent(GetParkingLots.this, DisplayVacantParkingLots.class);
            Log.i(TAG, "Inside getNearByParkingLots");
            Log.i(TAG, "Value of fromString" + fromTimeString);
            long lFromVal = DateTimeHelpers.convertToLongFromTime(fromTimeString);
            Log.i(TAG, "Value of ToString" + toTimeString);
            long lToVal = DateTimeHelpers.convertToLongFromTime(toTimeString);
            if ((lToVal - lFromVal) < Constants.thrityMinInMilliSeconds) {
                final AlertDialog alertDialog = new AlertDialog.Builder(GetParkingLots.this).create();

                alertDialog.setMessage("You have to park the car for at least 30 min");

                alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {

                        alertDialog.dismiss();
                    }
                });

                alertDialog.show();

            } else {
                intent.putExtra(LATITUDE, latitude);
                intent.putExtra(LONGITUDE, longitude);
                intent.putExtra(FROMTIME, lFromVal);
                intent.putExtra(TOTIME, lToVal);
                intent.putExtra(RadiusOrZIPCODE, isRadiusIndicator);
                if (isRadiusIndicator)
                    try {

                        intent.putExtra(RADIUS, Double.parseDouble(radius));
                        startActivity(intent);
                    } catch (Exception e) {
                        final AlertDialog alertDialog = new AlertDialog.Builder(GetParkingLots.this).create();

                        alertDialog.setMessage("Enter valid radius");

                        alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {

                                alertDialog.dismiss();

                            }
                        });

                        alertDialog.show();
                    }
                else {
                    try {

                        intent.putExtra(ZIPCODE, Long.parseLong(zipcode));
                        startActivity(intent);
                    } catch (Exception e) {
                        final AlertDialog alertDialog = new AlertDialog.Builder(GetParkingLots.this).create();

                        alertDialog.setMessage("Enter a valid Zip code");

                        alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                alertDialog.dismiss();

                            }
                        });

                        alertDialog.show();
                    }
                }

            }

        }
    });

}

From source file:com.example.mapdemo.MyLocationDemoActivity.java

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

    setContentView(R.layout.my_location_demo);

    ButterKnife.bind(this);

    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(map);
    mapFragment.getMapAsync(this);

    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (ActivityCompat.checkSelfPermission(this,
            Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(this,
                    Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        return;//from ww  w.j a v a2 s  .  c  o m
    }
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, new PositionListener());

    alarm = RingtoneManager.getRingtone(getApplicationContext(),
            RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM));

    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            createDialogForProgrammedStop();
            handler.postDelayed(this, Constants.TIME);
        }
    }, Constants.TIME);

}

From source file:it.unime.mobility4ckan.MainActivity.java

private void enableGPS() {
    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    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(getApplicationContext(), "Avvio GPS Fallito", Toast.LENGTH_LONG).show();
        return;/*w  w w  .j a v a  2 s .  com*/
    }
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
}

From source file:au.gov.ga.worldwind.androidremote.client.Remote.java

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

    //Normally one shouldn't instantiate all these objects in the onCreate method,
    //as onCreate is called every time a configuration change occurs (orientation,
    //keyboard hidden, screen size, etc). But we are handling configuration changes
    //ourselves.// w w w. j  av a2  s  .c  o m

    //hide the status bar
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    //get local Bluetooth adapter
    bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (bluetoothAdapter == null) {
        Toast.makeText(this, R.string.bluetooth_unavailable, Toast.LENGTH_LONG).show();
        finish();
        return;
    }

    communicator = new AndroidCommunicator(this, bluetoothAdapter);
    communicator.addListener(this);

    remoteViewCommunicator = new SocketAndroidCommunicator(this);

    DatasetModelState datasetsState = new DatasetModelState(communicator, this);
    LayerModelState layersState = new LayerModelState(communicator, this);
    PlaceModelState placesState = new PlaceModelState(communicator, this);

    ItemModelState[] states = new ItemModelState[] { datasetsState, layersState, placesState };
    for (ItemModelState state : states) {
        itemModelStates.put(state.getModel().getId(), state);
        ItemModelFragmentMenuProvider menuProvider = new EmptyMenuProvider();
        if (state == placesState) {
            menuProvider = new PlacesMenuProvider(communicator);
        }
        menuProviders.put(state.getModel().getId(), menuProvider);
    }

    controlFragment = ControlFragment.newInstance(remoteViewCommunicator);
    datasetsFragment = ItemModelFragment.newInstance(datasetsState.getModel().getId(), false);
    layersFragment = ItemModelFragment.newInstance(layersState.getModel().getId(), false);
    flatLayersFragment = ItemModelFragment.newInstance(layersState.getModel().getId(), true);
    placesFragment = ItemModelFragment.newInstance(placesState.getModel().getId(), false);
    tabFragments = new Fragment[] { controlFragment, datasetsFragment, layersFragment, flatLayersFragment,
            placesFragment };

    //create the tabs
    getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    int[] tabIds = new int[] { R.string.controls_tab, R.string.datasets_tab, R.string.layers_tab,
            R.string.flat_layers_tab, R.string.places_tab };
    for (int i = 0; i < tabIds.length; i++) {
        ActionBar.Tab tab = getSupportActionBar().newTab();
        tab.setTag(tabIds[i]);
        tab.setText(tabIds[i]);
        tab.setTabListener(this);
        getSupportActionBar().addTab(tab);
    }

    getSupportActionBar().setDisplayShowTitleEnabled(false);
    getSupportActionBar().setHomeButtonEnabled(true);

    //setup the shake sensor
    sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    sensorListener.setOnShakeListener(new ShakeEventListener.OnShakeListener() {
        @Override
        public void onShake() {
            communicator.sendMessage(new ShakeMessage());
        }
    });

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

    // Define a listener that responds to location updates
    LocationListener locationListener = new LocationListener() {
        public void onLocationChanged(Location location) {
            if (isSendLocation()) {
                communicator.sendMessage(new LocationMessage(location.getLatitude(), location.getLongitude(),
                        location.getAltitude(), location.getAccuracy(), location.getBearing()));
            }
        }

        public void onStatusChanged(String provider, int status, Bundle extras) {
        }

        public void onProviderEnabled(String provider) {
        }

        public void onProviderDisabled(String provider) {
        }
    };
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
    //locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
}

From source file:com.google.android.apps.paco.ExperimentExecutorCustomRendering.java

private void getBestProvider(LocationManager lm) {
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_COARSE);
    criteria.setAccuracy(Criteria.ACCURACY_FINE);

    String bestProvider = lm.getBestProvider(criteria, true);
    if (bestProvider != null) {
        lm.requestLocationUpdates(bestProvider, 0, 0, this);
        location = lm.getLastKnownLocation(bestProvider);
        for (InputLayout input : locationInputs) {
            input.setLocation(location);
        }//from   ww w  .  j  a  v a2s  .c  om

    } else {
        new AlertDialog.Builder(this).setMessage(R.string.need_location).setCancelable(true)
                .setPositiveButton(R.string.enable_button, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        launchGpsSettings();
                        dialog.dismiss();
                    }
                }).setNegativeButton(R.string.cancel_button, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                }).create().show();
    }
}

From source file:com.microsoft.band.sdksample.SensorsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_sensors, container, false);

    senSensorManager1 = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE);
    senSensorManager2 = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE);

    senGyroscope = senSensorManager1.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
    senSensorManager1.registerListener(this, senGyroscope, SensorManager.SENSOR_DELAY_NORMAL);

    senAccelerometer = senSensorManager2.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    senSensorManager2.registerListener(this, senAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);

    mTableAcc = (TableLayout) rootView.findViewById(R.id.tableAcc);
    mTableAcc.setVisibility(View.GONE);

    mTextAccX = (TextView) rootView.findViewById(R.id.textAccX);
    mTextAccY = (TextView) rootView.findViewById(R.id.textAccY);
    mTextAccZ = (TextView) rootView.findViewById(R.id.textAccZ);
    mTextAngX = (TextView) rootView.findViewById(R.id.textPAngX);
    mTextAngY = (TextView) rootView.findViewById(R.id.textPAngY);
    mTextAngZ = (TextView) rootView.findViewById(R.id.textPAngZ);

    mTextLong = (TextView) rootView.findViewById(R.id.textLong);
    mTextLat = (TextView) rootView.findViewById(R.id.textLat);

    mTextTime = (TextView) rootView.findViewById(R.id.textTime);

    temp_list = new double[14];

    c = 0;//from   w w  w . j a  v  a  2  s  .com
    // Acquire a reference to the system Location Manager
    LocationManager locationManager = (LocationManager) getActivity()
            .getSystemService(Context.LOCATION_SERVICE);

    // Define a listener that responds to location updates
    LocationListener locationListener = new LocationListener() {
        public void onLocationChanged(Location location) {
            // Called when a new location is found by the network location provider.
            temp_list[12] = location.getLongitude();
            temp_list[13] = location.getLatitude();
            mTextLong.setText(Double.toString(temp_list[12]));
            mTextLat.setText(Double.toString(temp_list[13]));
        }

        public void onStatusChanged(String provider, int status, Bundle extras) {
        }

        public void onProviderEnabled(String provider) {
        }

        public void onProviderDisabled(String provider) {
        }
    };

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

    runnable.run();

    //
    // Gyro setup
    //
    mTableGyro = (TableLayout) rootView.findViewById(R.id.tableGyro);
    mTableGyro.setVisibility(View.GONE);

    mTextGyroAccX = (TextView) rootView.findViewById(R.id.textGyroAccX);
    mTextGyroAccY = (TextView) rootView.findViewById(R.id.textGyroAccY);
    mTextGyroAccZ = (TextView) rootView.findViewById(R.id.textGyroAccZ);
    mTextGyroAngX = (TextView) rootView.findViewById(R.id.textAngX);
    mTextGyroAngY = (TextView) rootView.findViewById(R.id.textAngY);
    mTextGyroAngZ = (TextView) rootView.findViewById(R.id.textAngZ);

    //
    // Contact setup
    //
    mTableContact = (TableLayout) rootView.findViewById(R.id.tableContact);
    mTableContact.setVisibility(View.GONE);
    mTextContact = (TextView) rootView.findViewById(R.id.textContact);

    turnOnSensors();

    return rootView;
}

From source file:a14n.geolocationdemo.MainActivity.java

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

    // Define a listener that responds to location updates
    LocationListener locationListener = new LocationListener() {
        public void onLocationChanged(Location location) {
            JSONObject locationAsJson = new JSONObject();
            try {
                locationAsJson.put("accuracy", location.getAccuracy());
                locationAsJson.put("provider", location.getProvider());
                locationAsJson.put("latitude", location.getLatitude());
                locationAsJson.put("longitude", location.getLongitude());
                locationAsJson.put("time", location.getTime());
            } catch (JSONException e) {
                Log.e(TAG, "JSON exception", e);
                return;
            }/*from  w  ww  .j  a  va  2s  .  c o m*/
            flutterView.sendToFlutter("locations", locationAsJson.toString(), null);
        }

        public void onStatusChanged(String provider, int status, Bundle extras) {
        }

        public void onProviderEnabled(String provider) {
        }

        public void onProviderDisabled(String provider) {
        }
    };

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

From source file:org.planetmono.dcuploader.ActivityUploader.java

@Override
public void onResume() {
    super.onResume();

    /* resume location query */
    if (locationEnabled) {
        LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationTracker);
        lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationTracker);
    }//from w w w.  j ava  2s.c  o m
}

From source file:org.planetmono.dcuploader.ActivityUploader.java

private void queryLocation(boolean enabled) {
    LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    if (enabled) {
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationTracker);
        lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationTracker);
        ((Button) findViewById(R.id.upload_ok)).setEnabled(false);
        findViewById(R.id.upload_location_progress).setVisibility(View.VISIBLE);
    } else {//from   w ww. j  av  a  2s. c  om
        lm.removeUpdates(locationTracker);
        ((Button) findViewById(R.id.upload_ok)).setEnabled(true);
        findViewById(R.id.upload_location_progress).setVisibility(View.INVISIBLE);
    }
}