Hi,
I m also trying to do the same application.
And managed to get lat-lon,date ,time. But this code works on
emulator(eclipse)
when i install the same apk on android phone it doesn,t work

my code is:
public class TestBroadcastActivity extends Activity implements
LocationListener
{
        private LocationManager myManager;
        private LocationListener loc;
    private TextView tv;
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        tv = (TextView) findViewById(R.id.TextView01);

       myManager =
(LocationManager)this.getSystemService(Context.LOCATION_SERVICE);

        myManager.requestLocationUpdates(myManager.GPS_PROVIDER, 3000,
0, locationListener);
    }
     LocationListener locationListener = new LocationListener()
    {
    public void onLocationChanged(Location location)
    {
                try
                {
                String s = "";
                s += "\tTime: "+location.getTime() + "\n";
                s += "\tLatitude:  " + location.getLatitude()  + "\n";
                s += "\tLongitude: " + location.getLongitude() + "\n";
                s += "\tAccuracy:  " + location.getAccuracy()  + "\n";
                tv.setText(s);
                }
                catch (Exception e)
                {
                        System.out.println("Exception------>"+e);
                }
    }

    public void onStatusChanged(String provider, int status, Bundle
extras) {}
    public void onProviderEnabled(String provider) {}
    public void onProviderDisabled(String provider) {}

    };

        public void onLocationChanged(Location location) {}
        public void onProviderDisabled(String provider) {}
        public void onProviderEnabled(String provider) {}
        public void onStatusChanged(String provider, int status, Bundle
extras) {}

}

On Aug 28, 1:38 pm, Bipin Sutariya <[email protected]> wrote:
> OK one change Toast.makeText requires show() method to show toast. I
> added it and still onLocationChange not called.
>
> On Aug 28, 1:32 pm, Bipin Sutariya <[email protected]> wrote:
>
> > Hi,
>
> > I am trying to develop application in which i need current lat/lang.
> > However onLocationChange method never get called.
>
> > Following is my code, and note that i have given all required
> > permission like android.permission.ACCESS_COARSE_LOCATION,
> > android.permission.ACCESS_FINE_LOCATION, android.permission.INTERNET
> > in manifest file. I can see gps icon on status bar that keep blinking
> > to find location, but never get success.
>
> > Can any one please help me on this.
>
> > public class LocationServiceActivity extends Activity implements
> > LocationListener{
> >     /** Called when the activity is first created. */
> >     @Override
> >     public void onCreate(Bundle savedInstanceState) {
> >         super.onCreate(savedInstanceState);
> >         setContentView(R.layout.main);
>
> >         LocationManager lm =
> > (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
>
> >         Boolean isGPSEnabled =
> > lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
> >         Boolean isNetworkEnabled =
> > lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
>
> >         if(isGPSEnabled)
> >         {
> >                 lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 
> > 0,
> > this);
> >         }
> >         else if(isNetworkEnabled)
> >         {
> >                 lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
> > 0, 0, this);
> >         }
> >         else
> >         {
> >                 Toast.makeText(this, "NO SERVICE ENABLED", 5000);
> >         }
>
> >     }
>
> >     public void onLocationChanged(Location location) {
> >         Toast.makeText(this, location.getLatitude()+"---
>
> > >"+location.getLongitude(), 5000);
>
> >     }
> >     public void onProviderDisabled(String provider) {
> >         // TODO Auto-generated method stub
>
> >     }
> >     public void onProviderEnabled(String provider) {
> >         // TODO Auto-generated method stub
>
> >     }
> >     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 Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to