I got this to work, but only after opening Google Maps app. If I open
GMaps and then hit back, re open my app, the listener start working.
Is this the expected behavior?

On Oct 21, 9:12 pm, Vinicius Carvalho <viniciusccarva...@gmail.com>
wrote:
> Hello there! I'm trying to create a simple app to test GPS
> integration. Using the emulator and geo fix commands from telnet I'm
> able to get it working as expected. But installing it on a device,
> when I click on the first button to start listening for updates I can
> see the the GPS is active (by the small radar icon) but, moving
> around, It never updates the textfields it were suppose to update.
>
> Any ideas?
>
> package com.furiousbob.android.gps;
>
> import android.app.Activity;
> import android.content.Context;
> import android.location.Location;
> import android.location.LocationListener;
> import android.location.LocationManager;
> import android.os.Bundle;
> import android.sax.TextElementListener;
> import android.util.Log;
> import android.view.View;
> import android.view.View.OnClickListener;
> import android.widget.Button;
> import android.widget.EditText;
> import android.widget.TextView;
>
> public class MainActivity extends Activity {
>     /** Called when the activity is first created. */
>
>       private boolean amIListening = false;
>
>     @Override
>     public void onCreate(Bundle savedInstanceState) {
>         super.onCreate(savedInstanceState);
>         setContentView(R.layout.main);
>         Button btn = (Button)this.findViewById(R.id.Button01);
>         Button btn2 = (Button)this.findViewById(R.id.Button02);
>
>         final LocationManager lm = (LocationManager)getSystemService
> (Context.LOCATION_SERVICE);
>         final LocationListener gpsListener = new MyGPSListener(this);
>
>         btn.setOnClickListener(new OnClickListener() {
>
>                         @Override
>                         public void onClick(View v) {
>                                 if(!amIListening){
>                                         lm.requestLocationUpdates("gps", 
> 5000, 0, gpsListener);
>                                         amIListening = true;
>                                 }
>                         }
>                 });
>
>         btn2.setOnClickListener(new OnClickListener() {
>
>                         @Override
>                         public void onClick(View v) {
>                                 if(amIListening){
>                                         lm.removeUpdates(gpsListener);
>                                         amIListening = false;
>                                 }
>
>                         }
>                 });
>     }
>
>     private class MyGPSListener implements LocationListener{
>
>         private Activity activity;
>
>         public MyGPSListener(Activity parent){
>                 this.activity = parent;
>         }
>
>                 @Override
>                 public void onLocationChanged(Location location) {
>                         Double lat = location.getLatitude();
>                         Double lon = location.getLongitude();
>                         Double alt = location.getAltitude();
>                         
> ((TextView)activity.findViewById(R.id.TextView01)).setText
> ("Latitude: " + lat);
>                         
> ((TextView)activity.findViewById(R.id.TextView02)).setText
> ("Longitude: " + lon);
>                         
> ((TextView)activity.findViewById(R.id.TextView03)).setText
> ("Altitude: " + alt);
>                 }
>
>                 @Override
>                 public void onProviderDisabled(String provider) {
>                         // TODO Auto-generated method stub
>
>                 }
>
>                 @Override
>                 public void onProviderEnabled(String provider) {
>                         // TODO Auto-generated method stub
>
>                 }
>
>                 @Override
>                 public void onStatusChanged(String provider, int status, 
> Bundle
> extras) {
>                         // TODO Auto-generated method stub
>
>                 }
>
>     }
>
> }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to