GPS WORKING ON Emulator But Not on actual device

Tutorials that use the MapActivity. Many using GPS functionality.

GPS WORKING ON Emulator But Not on actual device

Postby vipulshah2010 » Thu Mar 04, 2010 1:23 pm

My gps is working perfectly on the emulator
but on HTC Droid eris it is not working
The app is crashing on actual device.
plz help me
its really urgent!!!!!!!!!!!!!!!!!!!!

below is my code.

package org.GPS;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.Toast;

public class GPS extends Activity implements LocationListener
{

@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent i = new Intent();
ComponentName comp = new ComponentName("com.android.settings",
"com.android.settings.SecuritySettings");
i.setComponent(comp);
startActivity(i);
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,1, 1,this);
Location currentLocation = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if(currentLocation != null)
{
double Latitude = currentLocation.getLatitude();
double Longitude = currentLocation.getLongitude();
Toast.makeText(GPS.this,"Latitude="+Latitude+"\nLongitude"+Longitude,Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(GPS.this,"No GPS 1",Toast.LENGTH_LONG).show();
}

}

@Override
public void onLocationChanged(Location location)
{
if (location != null)
{
double longitude = location.getLongitude();
double latitude = location.getLatitude();
Toast.makeText(GPS.this,"Longiude="+longitude+"\nLatitude="+latitude,Toast.LENGTH_LONG).show();

}
else
{
Toast.makeText(GPS.this,"No GPS 2",Toast.LENGTH_LONG).show();
}

}

@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

}
}


permissions i have included!!! are as follows

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
vipulshah2010
Junior Developer
Junior Developer
 
Posts: 14
Joined: Tue Feb 09, 2010 7:50 am
Location: India

Top

Postby rafffel » Thu Mar 04, 2010 4:38 pm

i copy paste your code and it work but it open the setting view .
so toast appear with the longitude and latitude .
i am on archos 5 it.
and i have only
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
on the androidmanifest.xml
Do your gps signal is fixed?
rafffel
Freshman
Freshman
 
Posts: 8
Joined: Thu Mar 04, 2010 10:21 am

Postby vipulshah2010 » Fri Mar 05, 2010 10:59 am

Can u plz tell me in detail what you want to say.
i didn't get your point :(
i m simulating fake gps on emulator
i have attached a screen below.
but on my HTC droid eris my application is crashing by giving error ...................stopped unexpec..........
i m bugged of this error now
i tried to found the cause.but not getting
since even i have included all conditions also.
plz hlp me.... :cry:
vipulshah2010
Junior Developer
Junior Developer
 
Posts: 14
Joined: Tue Feb 09, 2010 7:50 am
Location: India

Postby rafffel » Fri Mar 05, 2010 11:25 am

very strange i have only copy past your code and it's work .
Try to launch on debug mode with eclipse and add breakpoint for try to see where it's bugged.
And where is firmware version 1.5 ,1.6 ,2.0 ,2.1?
rafffel
Freshman
Freshman
 
Posts: 8
Joined: Thu Mar 04, 2010 10:21 am

Postby vipulshah2010 » Fri Mar 05, 2010 11:32 am

i m using google api 1.5
and i want to tell u the biggest strange thing is it work flawlessly on emulator
but on my htc droid eris it crashed.
did u run this code on live device.(not emulator)
and did it work
??
vipulshah2010
Junior Developer
Junior Developer
 
Posts: 14
Joined: Tue Feb 09, 2010 7:50 am
Location: India

Postby eyespyus » Fri Mar 05, 2010 9:38 pm

It worked for me on moto Droid device. I used api 1.6 to build.
User avatar
eyespyus
Freshman
Freshman
 
Posts: 7
Joined: Fri Mar 05, 2010 9:31 pm

Top

Postby rafffel » Sat Mar 06, 2010 3:23 pm

Yes i used my real device to test it.
I build it on 1.6.
rafffel
Freshman
Freshman
 
Posts: 8
Joined: Thu Mar 04, 2010 10:21 am

Postby osa_ahlawy » Wed Mar 10, 2010 1:44 pm

I have not read the code, but I believe you used getLastKnownLocation(), so if you haven't used your gps before that would be the cause of the problem.
so if this is the case, you can download from android market the app called (compass) and use it to detect your location, and then try to run your app again.

I have suffered from this problem when my phone was new :) .
osa_ahlawy
Freshman
Freshman
 
Posts: 7
Joined: Thu Feb 18, 2010 12:52 pm

Top

Return to Map Tutorials

Who is online

Users browsing this forum: No registered users and 2 guests