Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8729059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:45:55+00:00 2026-06-13T08:45:55+00:00

I have a class named GPSSampleLocation There is a function to turn on gps

  • 0

I have a class named GPSSampleLocation

There is a function to turn on gps and based on that getting location

here gpsEnabled will be true but in my phone when I request for gps the GPS icon on above in my PHONE will be blinking … but it is not blinking also… and I am not getting data

public void getGPSLocation() {
    LocationManager mlocManager = (LocationManager) GPSSampleLocation.this
            .getSystemService(Context.LOCATION_SERVICE);
    boolean gpsEnabled = mlocManager
            .isProviderEnabled(LocationManager.GPS_PROVIDER);
    if (!gpsEnabled) {
        String provider = Settings.Secure.getString(
                getContentResolver(),
                Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
        if (!provider.contains("gps")) { // if gps is disabled
            final Intent poke = new Intent();
            poke.setClassName("com.android.settings",
                    "com.android.settings.widget.SettingsAppWidgetProvider");
            poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
            poke.setData(Uri.parse("3"));
            sendBroadcast(poke);
        }
    }
    gpsEnabled = mlocManager
            .isProviderEnabled(LocationManager.GPS_PROVIDER);
    System.out.println("GPS ENALBLE" + gpsEnabled);
    if (gpsEnabled) {
        mlocManager.requestLocationUpdates(
                LocationManager.GPS_PROVIDER, 0, 0,
                GPSSampleLocation.this);
    }
}

I have also used these permissions :

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:45:56+00:00Added an answer on June 13, 2026 at 8:45 am

    The following is my code to test RequestLocationUpdates and LocationManager and LocationListener.

    package com.test.locationmanager;
    
    import android.app.Activity;
    import android.content.Context;
    import android.location.Location;
    import android.location.LocationListener;
    import android.location.LocationManager;
    import android.location.LocationProvider;
    import android.os.Bundle;
    import android.widget.TextView;
    
    public class LocationManagerStatus extends Activity {
        private LocationManager locationManager;
        private TextView textView;
    
        private final LocationListener gpsLocationListener = new LocationListener() {
    
            @Override
            public void onStatusChanged(String provider, int status, Bundle extras) {
                switch (status) {
                case LocationProvider.AVAILABLE:
                    textView.setText(textView.getText().toString() + "GPS available again\n");
                    break;
                case LocationProvider.OUT_OF_SERVICE:
                    textView.setText(textView.getText().toString() + "GPS out of service\n");
                    break;
                case LocationProvider.TEMPORARILY_UNAVAILABLE:
                    textView.setText(textView.getText().toString() + "GPS temporarily unavailable\n");
                    break;
                }
            }
    
            @Override
            public void onProviderEnabled(String provider) {
                textView.setText(textView.getText().toString() + "GPS Provider Enabled\n");
            }
    
            @Override
            public void onProviderDisabled(String provider) {
                textView.setText(textView.getText().toString() + "GPS Provider Disabled\n");
            }
    
            @Override
            public void onLocationChanged(Location location) {
                locationManager.removeUpdates(networkLocationListener);
    
                textView.setText(textView.getText().toString() + "New GPS location: "
                        + String.format("%9.6f", location.getLatitude()) + ", "
                        + String.format("%9.6f", location.getLongitude()) + "\n");
    
            }
        };
    
        private final LocationListener networkLocationListener = new LocationListener() {
    
            @Override
            public void onStatusChanged(String provider, int status, Bundle extras) {
                switch (status) {
                case LocationProvider.AVAILABLE:
                    textView.setText(textView.getText().toString() + "Network location available again\n");
                    break;
                case LocationProvider.OUT_OF_SERVICE:
                    textView.setText(textView.getText().toString() + "Network location out of service\n");
                    break;
                case LocationProvider.TEMPORARILY_UNAVAILABLE:
                    textView.setText(textView.getText().toString() + "Network location temporarily unavailable\n");
                    break;
                }
            }
    
            @Override
            public void onProviderEnabled(String provider) {
                textView.setText(textView.getText().toString() + "Network Provider Enabled\n");
    
            }
    
            @Override
            public void onProviderDisabled(String provider) {
                textView.setText(textView.getText().toString() + "Network Provider Disabled\n");
            }
    
            @Override
            public void onLocationChanged(Location location) {
                textView.setText(textView.getText().toString() + "New network location: "
                        + String.format("%9.6f", location.getLatitude()) + ", "
                        + String.format("%9.6f", location.getLongitude()) + "\n");
    
            }
        };
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            textView = (TextView) findViewById(R.id.textview);
            locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    
        }
    
        @Override
        protected void onResume() {
            super.onResume();
    
            locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000, 0, networkLocationListener);
            locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000, 0, gpsLocationListener);
        }
    
        @Override
        protected void onPause() {
            super.onPause();
    
            locationManager.removeUpdates(networkLocationListener);
            locationManager.removeUpdates(gpsLocationListener);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class named toto which I send to a function that does
I have a Class named Constants that contains all the constant variable in my
I have a class named Foo that extends a class named Bar that extends
I have a class named xmlReader that have parse(String path) and parseXml(Document doc) methods.
I have a class named MyCart. Class MyCartClass { var $MyCart; function getCart(){ return
I have a class named CollectionPager which has a collection inside that of type
If you have a class named User and another class named Admin that extends
I have class named config that have private string variable named param. I need
I have a class named utility in my App_code folder that holds the logic
I have some class named myClass , and following structure in there: class myClass

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.