Example usage for android.location LocationManager NETWORK_PROVIDER

List of usage examples for android.location LocationManager NETWORK_PROVIDER

Introduction

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

Prototype

String NETWORK_PROVIDER

To view the source code for android.location LocationManager NETWORK_PROVIDER.

Click Source Link

Document

Name of the network location provider.

Usage

From source file:com.danvelazco.android.wear.emergencyalert.service.WearAlertService.java

/**
 * Trigger the alert by sending an SMS with a pre-configured message to a pre-configured phone number. Here we also
 * take user's preferences into consideration. A {@link Notification} is posted, only if the user has that option
 * enabled, and the last known location is sent immediately, only if the user has that option enabled.
 * <p/>/*  ww w. j av  a 2 s .com*/
 * Finally, if the option to send the location is enabled, the {@link FineLocationSMSIntentService} will be started
 * and the phone number will be passed as an {@link Intent} extra. The {@link FineLocationSMSIntentService} will
 * make sure to fetch a more accurate and current location point, then send it to the phone number passed when the
 * service was started, and then it will kill it self.
 */
private void triggerAlert() {
    // Get the user preferences
    final String smsNumber = mSharedPrefs.getString(AlertPreferencesActivity.PREF_KEY_SMS_NUMBER, null);
    final String smsMessage = mSharedPrefs.getString(AlertPreferencesActivity.PREF_KEY_SMS_MESSAGE,
            getString(R.string.default_emergency_message));
    boolean sendLocation = mSharedPrefs.getBoolean(AlertPreferencesActivity.PREF_KEY_SMS_MESSAGE_LOCATION,
            true);
    boolean showNotification = mSharedPrefs.getBoolean(AlertPreferencesActivity.PREF_KEY_SHOW_NOTIFICATION,
            true);

    // Only keep going if we have a valid message and phone number
    if (!TextUtils.isEmpty(smsNumber) && !TextUtils.isEmpty(smsMessage)) {
        if (showNotification) {
            // Only post the notification if the option is enabled
            showNotification();
        }

        // Send the SMS with the specific messaged to the specific phone number set by the user
        SMSUtil.sendSms(smsNumber, smsMessage);

        // Only send the phone's location if the option is enabled
        if (sendLocation) {
            // Get the last known location and send it to the specific phone number
            Location location = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
            if (location != null) {
                double latitude = location.getLatitude();
                double longitude = location.getLongitude();

                // Format the message with specific coordinates
                String message = String.format(getString(R.string.message_last_location),
                        Double.toString(latitude), Double.toString(longitude),
                        SMSUtil.getFormattedTimestamp(this, location.getTime()));

                // Send the SMS with the last known location
                SMSUtil.sendSms(smsNumber, message);
            }

            // Start the location service and pass the phone number as an extra
            Intent locationService = new Intent(this, FineLocationSMSIntentService.class);
            locationService.putExtra(FineLocationSMSIntentService.KEY_SMS_PHONE_NUMBER, smsNumber);
            startService(locationService);
        }
    }
}

From source file:com.jimandreas.android.designlibdemo.Leak1TestActivity.java

@SuppressLint("SetTextI18n")
@Override/*w  w w  .j  a  v  a2 s.com*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // setContentView(R.layout.leak_detail);
    ButterKnife.bind(this);

    Intent intent = getIntent();
    final String leakTestName = intent.getStringExtra(EXTRA_NAME);

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

    CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
    collapsingToolbar.setTitle(leakTestName);

    loadBackdrop();

    /**
     * This leak is courtesy of:
     *
     * https://medium.com/freenet-engineering/memory-leaks-in-android-identify-treat-and-avoid-d0b1233acc8#.9sanu6r7h
     */

    leak_title.setText(R.string.leak1);

    String desc_raw = "Switch between the activities by selecting the BottomNavigationView item."
            + " This should leak the listener in the code" + " and produce a LeakCanary response.\n\n"
            + "This leak is courtesy of the entry by: \n\n" + "<big><strong>Johan Olsson</big></strong>\n\n"
            + "on his post to medium.com titled:\n\n"
            + "<big><strong>Memory leaks in Androididentify, treat and avoid</big></strong>\n"
            + "\nFor more information, press the FAB (floating action button).";

    desc_raw = desc_raw.replace("\n", "<br>");
    Spanned desc;

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
        desc = Html.fromHtml(desc_raw, Html.FROM_HTML_MODE_LEGACY);
    } else {
        //noinspection deprecation
        desc = Html.fromHtml(desc_raw);
    }
    leak_text.setText(desc);

    /**
     * And here is the actual leak!
     */
    locationManager = (LocationManager) getSystemService(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) {

        //    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.
        Log.e(TAG, "******* Do not have Manifest permission for Location access!!");
        return;
    }

    try {
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, TimeUnit.MINUTES.toMillis(5),
                100, this);
    } catch (Exception e) {
        Toast.makeText(this, "Sorry can't do this test, no location service", Toast.LENGTH_LONG).show();
    }

    /*
     * FAB button (floating action button = FAB) to get more information
     *    No more snackbar - until it is "BottomNavigationView" sensitive...
     */
    more_button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(
                    "https://medium.com/freenet-engineering/memory-leaks-in-android-identify-treat-and-avoid-d0b1233acc8#.9sanu6r7h"));
            startActivity(intent);
        }
    });
}

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

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    setContentView(R.layout.store_map_view);
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.my_title);
    mActivity = this;
    settings = getSharedPreferences(PREFS_NAME, 0);

    backButton = (ImageButton) findViewById(R.id.btnLeft);
    backButton.setVisibility(ImageButton.INVISIBLE);
    //backButton.setBackgroundResource(R.drawable.back_button);
    backButton.setBackgroundResource(ImageUtils.getBackIamge());
    backButton.setOnClickListener(this);

    titleBarTextView = (TextView) findViewById(R.id.titleBarTextView);
    titleBarTextView.setText(TitleTextUtils.getMapViewTitleText());
    ((ImageButton) findViewById(R.id.btnRight)).setVisibility(ImageButton.INVISIBLE);
    //      mapView = (MapView) findViewById(R.id.mapview);
    //      mapView.setBuiltInZoomControls(true);
    //      mapOverlays = mapView.getOverlays();

    // first overlay
    //      drawable = getResources().getDrawable(R.drawable.map);
    //      itemizedOverlay = new MyItemizedOverlay(drawable, mapView,true);
    //// ww w .  ja v  a 2  s .  com
    //
    //      //mapOverlays.add(itemizedOverlay);
    //      drawable2 = getResources().getDrawable(R.drawable.marker2);
    //      itemizedOverlay2 = new MyItemizedOverlay(drawable2, mapView,false);
    //      GeoPoint point2 = new GeoPoint((int)(Double.parseDouble(DataUtil.locationInfo.getLatitude()) * 1E6 ), (int)(Double.parseDouble(DataUtil.locationInfo.getLongitude()) * 1E6));
    //      OverlayItem overlayItem4 = new OverlayItem(point2, "Current Location", 
    //            "");      
    //      itemizedOverlay2.addOverlay(overlayItem4);

    //      mapOverlays.add(itemizedOverlay2);
    //
    //
    //      final MapController mc = mapView.getController();
    //      mc.animateTo(point2);
    //      mc.setZoom(9);
    //
    //      DataUtil.mapScreen = true;
    //      loadStores();

    // Get the location manager
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    // Define the criteria how to select the locatioin provider -> use
    // default
    Criteria criteria = new Criteria();
    Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

    // Initialize the location fields
    if (location != null) {
        System.out.println("Provider " + provider + " has been selected.");
        processOnLocationChanged(location);
    } else {
        //         latituteField.setText("Location not available");
        //         longitudeField.setText("Location not available");
    }
}

From source file:com.nadmm.airports.LocationListFragmentBase.java

protected void startLocationUpdates() {
    if (ContextCompat.checkSelfPermission(getActivity(),
            Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
        mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
                30 * DateUtils.SECOND_IN_MILLIS, 0.5f * GeoUtils.METERS_PER_STATUTE_MILE, this);

        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
        boolean useGps = prefs.getBoolean(PreferencesActivity.KEY_LOCATION_USE_GPS, false);
        if (useGps) {
            mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
                    30 * DateUtils.SECOND_IN_MILLIS, 0.5f * GeoUtils.METERS_PER_STATUTE_MILE, this);
        }//from ww  w . j  a v  a 2  s .  c  o m
    } else if (!mPermissionDenied) {
        if (shouldShowRequestPermissionRationale(Manifest.permission.ACCESS_FINE_LOCATION)) {
            Snackbar.make(getView(), "FlightIntel needs access to device's location.",
                    Snackbar.LENGTH_INDEFINITE).setAction(android.R.string.ok, new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            requestPermissions(new String[] { Manifest.permission.ACCESS_FINE_LOCATION },
                                    PERMISSION_REQUEST_FINE_LOCATION);
                        }
                    }).show();
        } else {
            requestPermissions(new String[] { Manifest.permission.ACCESS_FINE_LOCATION },
                    PERMISSION_REQUEST_FINE_LOCATION);
        }
    }
}

From source file:com.cmput301w17t07.moody.EditMoodActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    UserController userController = new UserController();
    userName = userController.readUsername(EditMoodActivity.this).toString();
    setContentView(R.layout.activity_edit_mood);
    setUpMenuBar(this);

    // get the mood object that was selected
    Intent intent = getIntent();//  ww  w .j a va2  s .c o m
    editMood = (Mood) intent.getSerializableExtra("editMood");
    date = editMood.getDate();
    bitmapImage = (Bitmap) intent.getParcelableExtra("bitmapback");
    editBitmapImage = bitmapImage;
    deletedPic = (int) intent.getExtras().getInt("bitmapdelete");
    latitude = editMood.getLatitude();
    longitude = editMood.getLongitude();
    image = (ImageView) findViewById(R.id.editImageView);
    final TextView location = (TextView) findViewById(R.id.locationText);
    address = editMood.getDisplayLocation();
    location.setText(address);

    if (latitude == 0 && longitude == 0) {
        location1 = null;
    }
    displayAttributes();
    if (deletedPic == 1) {
        image.setImageBitmap(null);
    }

    //set up the button and imageButton
    ImageButton editLocation = (ImageButton) findViewById(R.id.location);
    editLocation.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            locationText = (TextView) findViewById(R.id.locationText);
            locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            //check available tools
            List<String> locationList = locationManager.getProviders(true);
            if (locationList.contains(LocationManager.GPS_PROVIDER)) {
                provider = LocationManager.GPS_PROVIDER;
            } else if (locationList.contains(LocationManager.NETWORK_PROVIDER)) {
                provider = LocationManager.NETWORK_PROVIDER;
            } else {
                Toast.makeText(getApplicationContext(), "Please check your permissions", Toast.LENGTH_LONG)
                        .show();
            }
            //check the permission
            if (ActivityCompat.checkSelfPermission(getApplicationContext(),
                    android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                    && ActivityCompat.checkSelfPermission(getApplicationContext(),
                            android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                // TODO: Consider calling
                Toast.makeText(getApplicationContext(),
                        "Getting location failed, Please check the application permissions", Toast.LENGTH_SHORT)
                        .show();
                return;
            }

            location1 = locationManager.getLastKnownLocation(provider);
            if (location1 == null) {
                latitude = 0;
                longitude = 0;
            } else {
                latitude = location1.getLatitude();
                longitude = location1.getLongitude();
            }

            //get the location name by latitude and longitude
            Geocoder gcd = new Geocoder(EditMoodActivity.this, Locale.getDefault());
            try {
                List<Address> addresses = gcd.getFromLocation(latitude, longitude, 1);

                if (addresses.size() > 0)
                    address = "  " + addresses.get(0).getFeatureName() + " "
                            + addresses.get(0).getThoroughfare() + ", " + addresses.get(0).getLocality() + ", "
                            + addresses.get(0).getAdminArea() + ", " + addresses.get(0).getCountryCode();
                location.setText(address);
            } catch (Exception e) {
                e.printStackTrace();
            }

            final ImageButton deleteLocation = (ImageButton) findViewById(R.id.deleteLocation);
            deleteLocation.setVisibility(View.VISIBLE);
            deleteLocation.setEnabled(true);
        }
    });

    editLocation.setOnLongClickListener(new View.OnLongClickListener() {
        public boolean onLongClick(View view) {
            moodMessage_text = Description.getText().toString();
            editMood.setMoodMessage(moodMessage_text);
            editMood.setDate(date);
            Intent editLocation = new Intent(EditMoodActivity.this, EditLocation.class);
            editLocation.putExtra("EditMood", editMood);
            editLocation.putExtra("bitmap", compress(editBitmapImage));
            startActivity(editLocation);
            return true;
        }
    });

    final ImageButton deleteLocation = (ImageButton) findViewById(R.id.deleteLocation);
    deleteLocation.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            location1 = null;
            locationText = (TextView) findViewById(R.id.locationText);
            address = null;
            locationText.setText(address);
            latitude = 0;
            longitude = 0;
            deleteLocation.setVisibility(View.INVISIBLE);
            deleteLocation.setEnabled(false);
        }
    });

    ImageButton editCameraButton = (ImageButton) findViewById(R.id.editCamera);
    editCameraButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            try {
                Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
                startActivityForResult(intent, 1);
            } catch (Exception e) {
                Intent intent = new Intent(getApplicationContext(), EditMoodActivity.class);
                startActivity(intent);
            }
        }
    });

    editCameraButton.setOnLongClickListener(new View.OnLongClickListener() {
        public boolean onLongClick(View view) {
            try {
                Intent intent = new Intent("android.intent.action.PICK");
                intent.setType("image/*");
                startActivityForResult(intent, 0);
            } catch (Exception e) {
                Intent intent = new Intent(getApplicationContext(), EditMoodActivity.class);
                startActivity(intent);
            }
            return true;
        }
    });

    ImageButton PickerButton = (ImageButton) findViewById(R.id.EditDate);
    PickerButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            innit();
            TimeDialog.show();
        }
    });
    Button submitButton = (Button) findViewById(R.id.button5);
    submitButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            moodMessage_text = Description.getText().toString();
            MoodController moodController = new MoodController();
            editBitmapImage = bitmapImage;
            AchievementManager.initManager(EditMoodActivity.this);
            AchievementController achievementController = new AchievementController();
            achievements = achievementController.getAchievements();
            achievements.firstTimeEditFlag = 1;
            achievementController.saveAchievements();

            if (!moodController.editMood(EmotionText, userName, moodMessage_text, latitude, longitude,
                    editBitmapImage, SocialSituation, date, address, editMood, EditMoodActivity.this)) {
                Toast.makeText(EditMoodActivity.this, "Mood message length is too long. Please try again",
                        Toast.LENGTH_SHORT).show();
            } else {
                Intent intent = new Intent(EditMoodActivity.this, TimelineActivity.class);
                startActivity(intent);
                finish();
            }
        }
    });

    // TODO button needs only display when image present in Mood
    final ImageButton deletePicture = (ImageButton) findViewById(R.id.deletePicture);
    if (editBitmapImage == null || deletedPic == 1) {
        deletePicture.setVisibility(View.INVISIBLE);
        deletePicture.setEnabled(false);
    }
    deletePicture.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            bitmapImage = null;
            editBitmapImage = null;
            image.setImageDrawable(null);
            deletePicture.setVisibility(View.INVISIBLE);
            deletePicture.setEnabled(false);
        }
    });
}

From source file:com.tvs.signaltracker.STService.java

private void InitBase() {
    Tel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    MyListener = new MyPhoneStateListener();

    mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    NetLocListener = new NETLocationListener();
    mlocManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 10, NetLocListener);
    Tel.listen(MyListener,//from   w ww  . j  a  v  a2 s . co m
            PhoneStateListener.LISTEN_SIGNAL_STRENGTHS | PhoneStateListener.LISTEN_CELL_LOCATION);
    //CommonHandler.Operator   =   Utils.DoOperator(Tel.getNetworkOperatorName());
    Operator x = CommonHandler.dbman.getOperator(CommonHandler.MCC, CommonHandler.MNC);
    if (x != null)
        CommonHandler.Operator = x.name;
    else
        CommonHandler.Operator = CommonHandler.MCC + "" + CommonHandler.MNC;
}

From source file:org.iransoil.collect.android.activities.GeoPointMapActivitySdk7.java

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

    if (savedInstanceState != null) {
        mLocationCount = savedInstanceState.getInt(LOCATION_COUNT);
    }/*from  w w  w  .j  ava 2s.c o m*/

    requestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.geopoint_layout_sdk7);

    Intent intent = getIntent();

    mLocationAccuracy = GeoPointWidget.DEFAULT_LOCATION_ACCURACY;
    if (intent != null && intent.getExtras() != null) {
        if (intent.hasExtra(GeoPointWidget.LOCATION)) {
            double[] location = intent.getDoubleArrayExtra(GeoPointWidget.LOCATION);
            mGeoPoint = new GeoPoint((int) (location[0] * 1E6), (int) (location[1] * 1E6));
        }
        if (intent.hasExtra(GeoPointWidget.ACCURACY_THRESHOLD)) {
            mLocationAccuracy = intent.getDoubleExtra(GeoPointWidget.ACCURACY_THRESHOLD,
                    GeoPointWidget.DEFAULT_LOCATION_ACCURACY);
        }
        mCaptureLocation = !intent.getBooleanExtra(GeoPointWidget.READ_ONLY, false);
    }

    /**
     * Add the MapView dynamically to the placeholding frame so as to not
     * incur the wrath of Android Lint...
     */
    FrameLayout frame = (FrameLayout) findViewById(R.id.mapview_placeholder);
    String apiKey = "017Xo9E6R7WmcCITvo-lU2V0ERblKPqCcguwxSQ";
    // String apiKey = "0wsgFhRvVBLVpgaFzmwaYuqfU898z_2YtlKSlkg";
    mMapView = new MapView(this, apiKey);
    mMapView.setClickable(true);
    mMapView.setId(R.id.mapview);
    LayoutParams p = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
    frame.addView(mMapView, p);

    mCancelLocation = (Button) findViewById(R.id.cancel_location);
    mCancelLocation.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Collect.getInstance().getActivityLogger().logInstanceAction(this, "cancelLocation", "cancel");
            finish();
        }
    });

    mMapController = mMapView.getController();
    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    mMapView.setBuiltInZoomControls(true);
    mMapView.setSatellite(false);
    mMapController.setZoom(16);

    // make sure we have a good location provider before continuing
    List<String> providers = mLocationManager.getProviders(true);
    for (String provider : providers) {
        if (provider.equalsIgnoreCase(LocationManager.GPS_PROVIDER)) {
            mGPSOn = true;
        }
        if (provider.equalsIgnoreCase(LocationManager.NETWORK_PROVIDER)) {
            mNetworkOn = true;
        }
    }
    if (!mGPSOn && !mNetworkOn) {
        Toast.makeText(getBaseContext(), getString(R.string.provider_disabled_error), Toast.LENGTH_SHORT)
                .show();
        finish();
    }

    if (mGPSOn) {
        Location loc = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        if (loc != null) {
            InfoLogger.geolog("GeoPointMapActivity: " + System.currentTimeMillis()
                    + " lastKnownLocation(GPS) lat: " + loc.getLatitude() + " long: " + loc.getLongitude()
                    + " acc: " + loc.getAccuracy());
        } else {
            InfoLogger.geolog("GeoPointMapActivity: " + System.currentTimeMillis()
                    + " lastKnownLocation(GPS) null location");
        }
    }

    if (mNetworkOn) {
        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;
        }
        Location loc = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        if (loc != null) {
            InfoLogger.geolog("GeoPointMapActivity: " + System.currentTimeMillis()
                    + " lastKnownLocation(Network) lat: " + loc.getLatitude() + " long: " + loc.getLongitude()
                    + " acc: " + loc.getAccuracy());
        } else {
            InfoLogger.geolog("GeoPointMapActivity: " + System.currentTimeMillis()
                    + " lastKnownLocation(Network) null location");
        }
    }

    mLocationOverlay = new MyLocationOverlay(this, mMapView);
    mMapView.getOverlays().add(mLocationOverlay);

    if (mCaptureLocation) {
        mLocationStatus = (TextView) findViewById(R.id.location_status);
        mAcceptLocation = (Button) findViewById(R.id.accept_location);
        mAcceptLocation.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Collect.getInstance().getActivityLogger().logInstanceAction(this, "acceptLocation", "OK");
                returnLocation();
            }
        });

    } else {

        mGeoPointOverlay = new Marker(mGeoPoint);
        mMapView.getOverlays().add(mGeoPointOverlay);

        ((Button) findViewById(R.id.accept_location)).setVisibility(View.GONE);
        ((TextView) findViewById(R.id.location_status)).setVisibility(View.GONE);
        mShowLocation = ((Button) findViewById(R.id.show_location));
        mShowLocation.setVisibility(View.VISIBLE);
        mShowLocation.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Collect.getInstance().getActivityLogger().logInstanceAction(this, "showLocation", "onClick");
                mMapController.animateTo(mGeoPoint);
            }
        });

    }

    if (mGeoPoint != null) {
        mMapController.animateTo(mGeoPoint);
    }
}

From source file:com.rizal.lovins.smartkasir.activity.SettingsActivity.java

private void location() {
    LocationManager mLocationManager = (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) {
        // 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  w  ww . j  a v a  2s. co m
    }
    Location location = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
    if (location != null) {
        new AlertDialog.Builder(SettingsActivity.this).setTitle("Location")
                .setMessage("lat: " + location.getLatitude() + ", long: " + location.getLongitude())
                .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                }).show();
    }
}

From source file:com.nextgis.uikobserver.MainActivity.java

private void requestLocationUpdates() {
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, currentLocationListener);
    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, currentLocationListener);
}

From source file:com.inloc.dr.StepService.java

@Override
public void onCreate() {
    Log.i(TAG, "[SERVICE] onCreate");
    super.onCreate();

    dtr = new DataRecorder();

    mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    showNotification();/*from w  w  w.jav a  2 s.c  om*/

    // Load settings
    mSettings = PreferenceManager.getDefaultSharedPreferences(this);
    mPedometerSettings = new PedometerSettings(mSettings);
    mState = getSharedPreferences("state", 0);

    mUtils = Utils.getInstance();
    mUtils.setService(this);

    acquireWakeLock();

    // Start detecting
    mStepDetector = new StepDetector();
    mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
    mLocationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
    mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);

    mTurnDetector = new TurnDetector();
    mTurnNotifier = new TurnNotifier();
    mTurnNotifier.addListener(mAngleListener);
    mTurnDetector.addTurnListener(mTurnNotifier);

    registerDetector();

    // Register our receiver for the ACTION_SCREEN_OFF action. This will make our receiver
    // code be called whenever the phone enters standby mode.
    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
    registerReceiver(mReceiver, filter);

    mStepDisplayer = new StepDisplayer(mPedometerSettings, mUtils);
    mStepDisplayer.setSteps(mSteps = mState.getInt("steps", 0));
    mStepDisplayer.addListener(mStepListener);
    mStepDetector.addStepListener(mStepDisplayer);

    lSteps = mSteps;
    mConnManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

    File mExternalRoot = android.os.Environment.getExternalStorageDirectory();
    mOutputDir = new File(mExternalRoot.getAbsolutePath() + "/datalogs/");
    // attempt to make output directory
    if (!mOutputDir.exists()) {
        mOutputDir.mkdirs();
    }
    // Used when debugging:
    // mStepBuzzer = new StepBuzzer(this);
    // mStepDetector.addStepListener(mStepBuzzer);

    // Start voice
    reloadSettings();

    // Tell the user we started.
    Toast.makeText(this, getText(R.string.started), Toast.LENGTH_SHORT).show();
}