Hi All,
I've been struggling with MockLocationProvider for two days and it
doesn't work for me. I'll try to download new sdk. But since it is
downloading now i can express what's not working for me:

Here is my Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android";
      package="pl.itigo.hw"
      android:versionCode="1"
      android:versionName="1.0">

        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION" />
        <uses-permission
android:name="android.permission.ACCESS_MOCK_LOCATION" />
    <application android:icon="@drawable/icon" android:label="@string/
app_name">
        <uses-library android:name="com.google.android.maps" />
        <activity android:name="pl.itigo.hw.HelloWorld"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category
android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-sdk android:minSdkVersion="3" />
</manifest>

HelloWorld.java:

public class HelloWorld extends MapActivity {
        LinearLayout linearLayout;
        MapView mapView;
        ZoomControls mZoom;
        MapController mController;
        TextView txView;

        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);
                txView = (TextView) findViewById(R.id.txView);
                mapView = (MapView) findViewById(R.id.mapview);
                mZoom = (ZoomControls) mapView.getZoomControls();
                linearLayout = (LinearLayout) findViewById(R.id.zoomview);
                linearLayout.addView(mZoom);
                mController = mapView.getController();

                LocationManager locationManager = (LocationManager) 
getSystemService
(LOCATION_SERVICE);
                PendingIntent pIntent = PendingIntent.getBroadcast(this, 0,
                                new Intent(), 0);
                Log.i("location", "Providers: " + 
locationManager.getAllProviders
());
                // new Thread(new MockGps(locationManager)).start();
                locationManager.requestLocationUpdates("gps", 0, 0, pIntent);
                locationManager.requestLocationUpdates("gps", 0, 0,
                                new LocationListener() {
                                        public void onLocationChanged(Location 
location) {
                                                String locationText = "Location 
changed, current location: "
                                                                + location;
                                                Log.i("hw", locationText);
                                                int lat = (int) Math
                                                                
.round(location.getLatitude() * 1E6);
                                                int lng = (int) Math
                                                                
.round(location.getLongitude() * 1E6);
                                                mController.animateTo(new 
GeoPoint(lat, lng));
                                        }

                                        public void onProviderDisabled(String 
provider) {
                                                Log.i("hw", "Provider " + 
provider + " disabled");
                                        }

                                        public void onProviderEnabled(String 
provider) {
                                                Log.i("hw", "Provider " + 
provider + " enabled");

                                        }

                                        public void onStatusChanged(String 
provider, int status,
                                                        Bundle extras) {
                                                String info = "TEMPORARY 
UNAVAILABLE";
                                                if (status == 
LocationProvider.AVAILABLE) {
                                                        info = "AVAILABLE";
                                                } else if (status == 
LocationProvider.OUT_OF_SERVICE) {
                                                        info = "OUT OF SERVICE";
                                                }

                                                Log.i("hw", "Provider status 
changed:" + info);

                                        }

                                });

        }

        @Override
        protected boolean isRouteDisplayed() {
                return false;
        }
}


Then i've connected with DDMS and sending any gps locations doesn't
work. Neither gpx nor kml files doesn't load to the ddms view too. So
I've connected with adb shell to see /data/misc/location/
<provider_name> folder. But it is missing there is only /data/misc/
hcid directory. Nothing in /data/app folder interesting as well. After
that i've decided to write simple code to mimic gps, here it is:

MockGPS.java:

public class MockGps implements Runnable {
        public static final String PROVIDER_NAME = "test1";
        private LocationManager manager;

        public MockGps(LocationManager manager) {
                this.manager = manager;
                try {
                        manager.addTestProvider(PROVIDER_NAME, false, false, 
false, false,
false, false, false, 0, 1);
                } catch (IllegalArgumentException e) {
                        e.printStackTrace();
                }
                manager.setTestProviderEnabled(PROVIDER_NAME, true);
        }
        public void run() {
                Location l = new Location(PROVIDER_NAME);
                l.setLongitude(30.456789);
                l.setLatitude(-19.234567);
                manager.setTestProviderLocation(PROVIDER_NAME, l);
                Random rand = new Random();
                while(true) {
                        double lat = l.getLatitude();
                        double lng = l.getLongitude();
                        l.setLatitude(lat+rand.nextDouble());
                        l.setLongitude(lng+rand.nextDouble());
                        manager.setTestProviderLocation(PROVIDER_NAME, l);

                        try {
                                Thread.sleep(1000);
                        } catch (InterruptedException e) {
                                Log.e("hw", e.toString());
                        }
                        manager.setTestProviderStatus(PROVIDER_NAME,
LocationProvider.AVAILABLE, null, 50);
                }
        }

}

I've tried both 1.1 and 1.5 SDK neither of those works for me.

Here is LogCat:

05-19 11:56:30.350: DEBUG/LocationManager(732): Constructor: service =
android.location.ilocationmanager$stub$pr...@435c7ab8
05-19 11:56:30.359: DEBUG/LocationManager(732): getAllProviders
05-19 11:56:30.369: INFO/location(732): Providers: [gps, network]
05-19 11:56:30.369: DEBUG/GpsLocationProvider(570): setMinTime 0
05-19 11:56:30.389: DEBUG/GpsLocationProvider(570): setMinTime 0
05-19 11:56:30.528: INFO/MapActivity(732): Handling network change
notification:CONNECTED
05-19 11:56:30.540: ERROR/MapActivity(732): Couldn't get connection
factory client
05-19 11:56:31.278: INFO/ActivityManager(570): Displayed activity
pl.itigo.hw/.HelloWorld: 2207 ms
05-19 11:56:31.420: INFO/hw(732): Provider status changed:TEMPORARY
UNAVAILABLE

After pushing some gps data with DDMS:

05-19 11:58:08.968: INFO/hw(732): Provider status changed:AVAILABLE


And thats all. Please help me with this issue, otherwise i'll get grey
hair. I didn't even try to upload app to the (real) device.




--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to