Hi,
I have a short script, which is pasted below, to test the Location Management
function on a production device. The code works well in the emulator and
captures the location as expected when it is fixed using the DDMS application
in Eclipse.
However, when I try it on a production device (HTC Hero - SDK 1.5 in this
case), I get no response at all.
Does anybody have an idea why it does not work as expected or have a similar
experience on a production device ?
Cheers,
Emre
Here's the code:
package ...
import android.app.Activity;
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.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class LocationFinderTest extends Activity {
private Context mPackageContext = this;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.location_test_layout);
String context = Context.LOCATION_SERVICE;
String provider = LocationManager.GPS_PROVIDER;
LocationManager locationManager;
LocationListener locationListener = new LocationListener(){
public void onLocationChanged(Location location) {
if (location == null) {
Log.w("LocationFinderTest", "Location has been
updated to NULL");
} else {
updateWithNewLocation(location);
}
}
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
}
};
locationManager = (LocationManager)getSystemService(context);
/*
* The getLastKnownLocation method will return null until the
provider
* you specify has gotten at least one update. In practice that
means
* you need to have an application (any application, doesn't
have to
* be the one your testing) request (and receive) updates at
least once
* in your emulator session before it will getLastKnown will
return a
* value. You can disable the updates after the first return if
you want
* to.
*/
locationManager.requestLocationUpdates(provider,0,0,locationListener);
final Button button = (Button)
findViewById(R.id.mylocation_button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
Intent i = new Intent(mPackageContext, MapViewer.class);
startActivity(i);
}
});
}
private void updateWithNewLocation(Location location)
{
TextView myLocationText;
myLocationText = (TextView)findViewById(R.id.myLocationText);
if (location != null)
{
double lat = location.getLatitude();
double lng = location.getLongitude();
myLocationText.setText("Your Current Position is \n
Lat:" +lat+"\n Long:"+lng );
} else
{
myLocationText.setText("Your Location Could NOT Be
Found");
}
}
}
All the necessary permissions are in the Manuscript file, such as:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
_________________________________________________________________
Stay in touch.
http://go.microsoft.com/?linkid=9712959
--
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