开发者

emulate gps location in the android Emulator.

I had some problem when I try to send emulator gps coordination to Android emulator via DDMS.

I have created a quite simple demo code:

//gps.java

package com.trackingsolutions.gps;

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

public class GPS extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {        
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        LocationListener locationListener = new LocationListener() {
            public void onLocationChanged(Location location) {          
            String lat = String.valueOf(location.getLatitude());
                String lon = String.valueOf(location.getLongitu开发者_Python百科de());
                Log.i("NOTIFICATION","onLocationChenged Triggered");
                Toast.makeText(GPS.this,"location changed: lat="+lat+", lon="+lon, Toast.LENGTH_LONG).show();            
            }
            public void onStatusChanged(String provider, int status, Bundle extras) {}
            public void onProviderEnabled(String provider) {}
            public void onProviderDisabled(String provider) {}
        };
        LocationManager locationManager = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
    }
}

and I do remembered to enable the access for gps on AndroidManifest.xml:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

When I try to test the code on the simulator, I turned on two debug tag:

On the Device Tag, I can see the com.trackingsolutions.gps is up and running, I clicked the green symbol to make it active for debug.

Then on the Emulator Control Tag, I can see the testing information as : Longitude: -122.084095, Latitude: 37.422006.

Here is my problem, every time I click on the send button, all of the running process include my gps application crashes. Feels like lock up.

I tried to use the telnet to send the gps fix, and it's still the same.

Frustrated for whole day, can anyone give me some idea? Many thanks in advance.

BTW, the build target I choose is : Google API, platform 2.3.3, API level 10.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜