You need to use permission first:

Copy<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Next you inside onCreate() method use below code to get access to GPS.

Copy@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
            2000, 1, this);

}

Now if GPS is not enabled then you need to refer below code. For detailed explanation, you can refer how to get[DEAD LINK] [current location in android]1 tutorial.

CopyIntent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
         startActivity(intent);

Here we have used intents to redirect user to location settings page so that he can enable the GPS under location settings.

Answer from amit duhan on Stack Overflow
🌐
Android Developers
stuff.mit.edu › afs › sipb › project › android › docs › training › basics › location › locationmanager.html
Using the Location Manager | Android Developers
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); While not required, most modern Android-powered devices can receive location updates through multiple underlying technologies, which are abstracted to an application as LocationProvider objects.
🌐
TutorialsPoint
tutorialspoint.com › android-gps-location-manager-tutorial
Android GPS, Location Manager tutorial
This example demonstrates how to access Android GPS, Location Manager · Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml.
Discussions

service - How to use Android LocationManager and Listener - Stack Overflow
I'm not having any luck receiving any data from the GPS using the code below, and i'm not sure what I'm doing wrong, it seems like my code matches everything i see online. i'd like to eventually ad... More on stackoverflow.com
🌐 stackoverflow.com
How does LocationManager.NETWORK_PROVIDER internally work?
I can recommend you the latest episode of the android developer backstage podcast where they talk about the technologies involved locating your device. It really blew my mind how complex and challenging the whole topic is. It really is a huge topic. https://podcasts.apple.com/de/podcast/android-developers-backstage/id785545036?i=1000618409603 They basically have a database with all cell towers and their location as well as all wifi networks and their location an android phone with playservices was ever connected to. So it’s just a database lookup for your Wi-Fi MAC address and/or you cell tower ID. More on reddit.com
🌐 r/androiddev
3
1
July 12, 2023
Download location for CIFS Manager / Mount Manager
I have their latest Play Store versions saved. Where and how can I easy and anonymously upload them? You do know most roms do not support smb/cifs mounting anymore since JB? More on reddit.com
🌐 r/androidapps
6
4
October 30, 2015
Managing files in the "Android/data" folder on Android 11 (without root or USB)

Once again the iron grip of Google on AOSP, so many AOSP apps are frozen in favor of Google apps.

More on reddit.com
🌐 r/Android
111
237
October 2, 2020
🌐
Technobyte
technobyte.org › locationmanager-tutorial-android-studio
LocationManager Tutorial in Android
April 21, 2024 - In this tutorial, we will learn how to get the user’s location coordinates – Latitude, Longitude and Altitude by building a simple Android Application that will use the LocationManager class.
🌐
Vogella
vogella.com › tutorials › AndroidLocationAPI › article.html
Android Location API with the fused location provider - Tutorial
February 26, 2026 - This can be done via a GPS (Global Positioning System) module, via cell tower triangulation and via wifi networks. Google Play provides the fused location provider to retrieve the device’s last known location. To use the location manager make the Google play service available via your app build....
🌐
Android Developers
developer.android.com › api reference › locationmanager
LocationManager | API reference | Android Developers
Skip to main content · English · Deutsch · Español – América Latina · Français · Indonesia · Polski · Português – Brasil · Tiếng Việt · 中文 – 简体
Top answer
1 of 2
3

You need to use permission first:

Copy<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Next you inside onCreate() method use below code to get access to GPS.

Copy@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
            2000, 1, this);

}

Now if GPS is not enabled then you need to refer below code. For detailed explanation, you can refer how to get[DEAD LINK] [current location in android]1 tutorial.

CopyIntent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
         startActivity(intent);

Here we have used intents to redirect user to location settings page so that he can enable the GPS under location settings.

2 of 2
1

you can achieve this easily. you have to write code in main activity. and Main activity implements Locationlistner interface. and overload its four methods. here i'am retrieving my Longitude and Latitide co-ordinates in a textview when application started. and you have to give permission for access location in your manifest file.

as under my code.

Copypackage com.nisarg.gpsdemo;

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements LocationListener {

    private LocationManager locationManager;
 private TextView textview;

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

        textview=(TextView)findViewById(R.id.textView);

        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;
        }
        Location location = locationManager.getLastKnownLocation(locationManager.NETWORK_PROVIDER);

        onLocationChanged(location);
    }

    @Override
    public void onLocationChanged(Location location) {
        double longitude=location.getLongitude();
        double latitude=location.getLatitude();
        textview.setText("Longitude:   "+longitude+"   Latitide:  "+latitude);

    }

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

    }

    @Override
    public void onProviderEnabled(String s) {

    }

    @Override
    public void onProviderDisabled(String s) {

    }
}

and you have to give permission like this in manifest file.

Copy <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

And last warning. you have to give permission to your application and start mobile data and GPS before you open application. either it will be crashed.

that's it. hope it will help you. :)

🌐
Medium
medium.com › @psarakisnick › android-location-manager-with-kotlin-flows-082c992d1b31
Android location manager with Kotlin flows | by Nick Psarakis | Medium
January 21, 2024 - Android location manager with Kotlin flows One of the most common device resources used in mobile applications is the current device location, lets see how we can get it in a clean way using Kotlin …
Find elsewhere
🌐
ProTech
protechtraining.com › blog › post › tutorial-android-location-service-example-198
Tutorial: Android Location Service Example - ProTech Training
April 28, 2011 - Hi folks, This tutorial will help you to start using location services (in particular: LocationManager class to get user location and Geocoder to translate location into addresses) and Google Maps on Android.
🌐
Medium
medium.com › pickme-engineering-blog › building-a-modern-android-location-manager-from-legacy-approaches-to-clean-architecture-excellence-3e3e4590533e
Building a Modern Android Location Manager: From Legacy Approaches to Clean Architecture Excellence | by Chamod Lakmal | The PickMe Engineering Blog | Medium
September 16, 2025 - The project seamlessly integrates with Android’s modern permission system, checking for both fine and coarse location permissions and providing clear error messages when permissions are denied. This eliminates the guesswork often associated with permission related location failures. Where traditional location implementations required developers to understand the intricacies of location providers, callback management, and manual cleanup, this modern approach provides four simple methods that cover all common use cases: getLastLocation for quick cached results, getCurrentLocation for immediate fresh location data, getCurrentLocationUpdates for continuous tracking, and getProximateLocation for the most accurate available location.
🌐
Dartmouth College
cs.dartmouth.edu › ~campbell › cs65 › lecture17 › lecture17.html
Location-Based Service –
The Android location manager gives location in terms of longitude and latitude for the location of the phone.
🌐
TutorialsPoint
tutorialspoint.com › android › android_location_based_services.htm
Android - Location Based Services
This tutorial shows you how to use Location Services in your APP to get the current location, get periodic location updates, look up addresses etc.
🌐
DigitalOcean
digitalocean.com › community › tutorials › android-location-api-tracking-gps
Android Location API to track your current location | DigitalOcean
August 3, 2022 - Depending on the conditions, this ... than GPS_PROVIDER · In this tutorial, we’ll create a Service that implements the LocationListener class to receive periodic location updates via GPS Providers or Network Providers....
🌐
Android Developers
stuff.mit.edu › afs › sipb › project › android › docs › training › basics › location › currentlocation.html
Obtaining the Current Location | Android Developers
The LocationManager class exposes ... simplest form, you register an event listener, identify the location manager from which you'd like to receive location updates, and specify the minimum time and distance intervals at which to receive location updates....
🌐
Medium
sachankapil.medium.com › latest-method-how-to-get-current-location-latitude-and-longitude-in-android-give-support-for-c5132474c864
Latest Method: How to get Current Location (Latitude and Longitude) in Android & Give support for…
January 27, 2023 - How to get the Current Location (Latitude and Longitude) in Android This tutorial helps you to learn How to get the current latitude and longitude in the Android. As a developer when you work on …
🌐
GitHub
github.com › MuhammadMuzammilSharif › LocationManager
GitHub - MuhammadMuzammilSharif/LocationManager: a demo that let you get user location in android (even in the absence of internet)
A location Manager demo that let you get device current location using fused location provider (i.e. works even in the absence of internet).
Author   MuhammadMuzammilSharif
🌐
Edureka
edureka.co › blog › location-based-services-in-android
Location based Services in Android Tutorial | Edureka
April 28, 2020 - These classes and interface are ... in Android. Classes and Interfaces of Location Based Services: LocationManager – This class helps to get access to the location service of the system.
🌐
Vanderbilt
dre.vanderbilt.edu › ~schmidt › android › android-4.0 › out › target › common › docs › doc-comment-check › reference › android › location › LocationManager.html
LocationManager | Android Developers
Name of the GPS location provider. This provider determines location using satellites. Depending on conditions, this provider may take a while to return a location fix. Requires the permission android.permission.ACCESS_FINE_LOCATION.
🌐
GeeksforGeeks
geeksforgeeks.org › android › how-to-get-current-location-in-android
How to Get Current Location in Android? - GeeksforGeeks
Android’s Location Manager API · Fused Location Provider: Google Play Services Location APIs · Question: Which one is efficient and why? Answer: Fused Location Provider because it optimizes the device’s use of battery power. Before moving any of the above methods we will have to take location permission.
Published   July 23, 2025
🌐
Medium
medium.com › @boobalaninfo › accessing-users-location-guide-android-2023-60a6f018a718
Accessing User’s Location Guide Android 2023 | by Boobalan Munusamy | Medium
June 22, 2023 - Accessing User’s Location Guide Android 2023 Jetpack Compose + Hilt Android+ Hilt Worker + Coroutine Worker + Foreground Service + Work Manager + MVVM Design Pattern Accessing user’s current …