Reputation: 1411
I am testing my application in Android Emulator and I am only able to set a GPS position when the application is already running through the onLocationChanged
method. I can't set it before I start the application. This is the code in my onCreate
method:
Edit: Think you guys missunderstood me. I am able to set a GPS position with geo fix when application is running. When I try to set it before I launch the activity I get Error android.view.windowmanager$badtokenexception.
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
Criteria crit = new Criteria();
providers = lm.getBestProvider(crit, false);
loc = lm.getLastKnownLocation(providers);
if (loc != null) {
title.setText(stop_name);
lview.setAdapter(lviewAdapter);
} else {
Toast t = Toast.makeText(this, "Failed to get GPS location", 5000);
t.setGravity(Gravity.BOTTOM, 0, 0);
t.show();
}
Upvotes: 1
Views: 276
Reputation: 6686
You even don't need to open command line tool, if you are using eclipse [I hope you do], if not you don't have to reed the rest....
Upvotes: 1
Reputation: 3313
As you can see in the image you can send lat/long manually from your eclipse by going to DDMS an add lat/long values manually and send it you can get these points in your emulator by doing this
Upvotes: 1
Reputation: 6128
to set the gps location in emulator you have to follow below steps and open your app before setting up below steps ,then this will go to last configuration .
Upvotes: 1