Here is my code. I use eclipse with an avd and i sent it the coordinates i want. I saw that if a use an avd with API 7 or higher, my application works fine, but if i use an avd with API 3, it accept only 3 points and then it stops accepting other coordinates (i still don't know if there is the same problems with api 4-5-6 because i'm trying it now). EDIT: API 4 is ok.
public class myActivity extends Activity
{
private TextView mytext;
private LocationManager locmgr = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
GPSListener gpsListener=newGPSListener();
mytext = (TextView) findViewById(R.id.mytext);
//grab the location manager service
locmgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locmgr.requestLocationUpdates(locmgr.GPS_PROVIDER, 10, 10, gpsListener);
mytext.setText("waiting for location");
}
//Start a location listener
private class GPSListener implements LocationListener
{
public void onLocationChanged(Location loc)
{
//sets and displays the lat/long when a location is provided
String latlong = "Lat: " + loc.getLatitude() + " Long: " + loc.getLongitude();
mytext.setText(latlong);
}
public void onProviderDisabled(String provider)
{
}
public void onProviderEnabled(String provider)
{
}
public void onStatusChanged(String provider, int status,
Bundle extras)
{
}
}
}
Mmh can't say what's really happening, but I'd suggest not to concern about Api Levels prior 8 (2.2).
As you can see in Android Developer Dashboards , android users prior Api level 8 have literally disappeared (even Api level 8 is almost 'deprecated')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.