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

  • SEARCH
  • Home
  • 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 6588463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:03:04+00:00 2026-05-25T17:03:04+00:00

Here is a code below that suppose to listen for GPS updates and send

  • 0

Here is a code below that suppose to listen for GPS updates and send notifications to main activity

However it does not seem to be working 🙂

No errors, only onLocationChanged is not called!

Funny thing is: when I run some other app to get GPS fix and after that start my app => onLocationChanged gets called, only accuracy is degrading, and eventually fix is lost.

I also tried to add to this code GPS listener=> it works, satellites in view got reported every second, only fix is never accuired.

What the hell is going on? 🙂

public class PhoneGPSpos{

private Handler myHandler = null;
private LocationManager lm;
private LocationListener locationListener;
private Location currentBest;
Context m_context;

public PhoneGPSpos(Context context, Handler handler) {

    myHandler = handler;
    m_context = context;


    lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);

 //  Bundle bundle = new Bundle();
 //  boolean xtraInjection=lm.sendExtraCommand(LocationManager.GPS_PROVIDER,"force_xtra_injection",bundle);
 //  boolean timeInjection=lm.sendExtraCommand(LocationManager.GPS_PROVIDER,"force_time_injection",bundle);

   currentBest = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);

    locationListener = new LocationListener() 
   { 

           public void onLocationChanged(Location location)
           { 
                Log.w("Compass", "Loc");

            if (location != null)
            {
                currentBest = location;

                Message msg = new Message();

                msg.arg1 = 5;
                myHandler.sendMessage(msg);

            }
           } 

           public void onStatusChanged(String provider, int status, Bundle 
           extras) {
            Log.d("Compass", "Stat");
           } 

           public void onProviderEnabled(String provider) {
            Log.d("Compass", "Prov e");
           } 

           public void onProviderDisabled(String provider) {
            Log.d("Compass", "Prov d");
        } 
   }; 
}

public void requestGPS()
{
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
    Log.d("Compass", "gps requested");
}

public void stopGPS()
{
    Log.d("Compass", "gps stopped");
    lm.removeUpdates(locationListener);
}

public synchronized  Location getBest()
{
    return  currentBest;
}

}

  • 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-05-25T17:03:05+00:00Added an answer on May 25, 2026 at 5:03 pm

    Ok, figure out that this is an issue that was also seen by other people: apparently (at least on some phones) GPS listener works much worse if Camera is active.

    Problem with getting GPS data when using CameraPreview

    Android: Losing GPS signal strength on some phones when I start up the Camera and SurfaceView

    Camera Preview and GPS reading in Android

    Created Andorid issue for that http://code.google.com/p/android/issues/detail?id=20098

    If someone has a solution pls share

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I commented my code below to reflect what I am attempting to do here.
Hey all. Here is the scenario. I have the below code, and I'm needing
I'm trying to update an element in the XML document below: Here's the code:
enter code here Hi All, I have a simple windows service application that connects
I suppose that this is an interesting code example. We have a class --
Here's the error I'm getting with the code pasted below. Unable to create instance
As a toy example, suppose that we have a function called 'my_func' (the code
I have some html code that look like this sample here : <html> <body>
Ok the error is showing up somewhere in this here code if($error==false) { $query
Here is code from MSDN . I don't understand why the work isn't just

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.