Hi guys,

This is my first android app...

I have a problem, this app work only on google maps and not on others
navigator software like copilot. Copilot tell me there is not gps
signal...

Pls help me


import android.location.Location;
import android.location.LocationManager;
import android.location.LocationProvider;
import android.os.Handler;

public class LocationMock {

        private static String GPS_PROVIDER_NAME = "gps";

        private int mMockLocationSecondsPassed = 0;
        private int mMockLocationCurrentIndex = -1;

        private Handler mMockLocationHandler = new Handler();

        private LocationManager mLocationManager = null;
        private Location currentLocation = null;

        private double[][] mMockLocations = new double[][] {
                        { 53.14131, 8.20885 },
                        { 53.14153, 8.20318 },
                        { 53.14212, 8.19638 },
                        { 53.14417, 8.19142 },
                        { 53.14581, 8.18793 },
                        { 53.14808, 8.18876 },
                        { 53.15014, 8.19162 },
                        { 53.14913, 8.20005 },
                        { 53.14871, 8.20582 },
                        { 53.14677, 8.20953 },
                        { 53.14251, 8.21052 }
        };

        public LocationMock(LocationManager pLocationManager) {

                mLocationManager = pLocationManager;

        }

        private Runnable mMockLocationRunnable = new Runnable() {

                public void run() {

                        if (++mMockLocationSecondsPassed == 5) {
                                getMockLocation();
                                mMockLocationSecondsPassed = 0;
                        }

                        mMockLocationHandler.postDelayed(this, 1000);
                }

        };

        public void startMockupLocationCycling() {

                if (mLocationManager.getProvider(GPS_PROVIDER_NAME) != null) {
                          
mLocationManager.removeTestProvider(GPS_PROVIDER_NAME);
                        }


                mLocationManager.addTestProvider(
                                GPS_PROVIDER_NAME,
                                "requiresNetwork" == "",
                                "requiresSatellite" == "",
                                "requiresCell" == "",
                                "hasMonetaryCost" == "",
                                "supportsAltitude" == "",
                                "supportsSpeed" == "",
                                "supportsBearing" == "",

                                android.location.Criteria.POWER_LOW,
                                android.location.Criteria.ACCURACY_FINE
                );

                getMockLocation();
                mMockLocationRunnable.run();
        }

        private void getMockLocation() {

                double[] mockLocationLatLng = mMockLocations[+
+mMockLocationCurrentIndex % mMockLocations.length];

                currentLocation = new Location(GPS_PROVIDER_NAME);

                currentLocation.setLatitude(mockLocationLatLng[0]);
                currentLocation.setLongitude(mockLocationLatLng[1]);
                currentLocation.setTime(System.currentTimeMillis());
                currentLocation.setSpeed(200);

                currentLocation.setAccuracy(500);

                mLocationManager.setTestProviderLocation(GPS_PROVIDER_NAME,
currentLocation);

                mLocationManager.setTestProviderEnabled(GPS_PROVIDER_NAME, 
true);
                mLocationManager.setTestProviderStatus(GPS_PROVIDER_NAME,
LocationProvider.AVAILABLE, null, System.currentTimeMillis());

        }

}

=============================================================================


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.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class LocationSpoofer extends Activity {

        private static final long MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 1; //
in Meters
        private static final long MINIMUM_TIME_BETWEEN_UPDATES = 1000; // in
Milliseconds

    protected LocationManager lm;

        /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        Button cmdSend = (Button) findViewById(R.id.cmdSend);

        //final EditText txtLat = (EditText)
findViewById(R.id.txtLat);
        //final EditText txtLng = (EditText)
findViewById(R.id.txtLng);

        cmdSend.setOnClickListener(new View.OnClickListener() {

                public void onClick(View v)
                {

                        lm =
(LocationManager)getSystemService(Context.LOCATION_SERVICE);

//                      lm.requestLocationUpdates(
//                              LocationManager.GPS_PROVIDER,
//                              MINIMUM_TIME_BETWEEN_UPDATES,
//                              MINIMUM_DISTANCE_CHANGE_FOR_UPDATES,
//                              new MyLocationListener()
//                );

                        LocationMock locMock = new LocationMock(lm);

                        locMock.startMockupLocationCycling();

                        //LocationFeeder.init(getApplicationContext());
                //LocationFeeder.setMockLocation(15.387653, 73.872585,
500);
                //LocationFeeder.shutdown();
                }
        });
    }


        private class MyLocationListener implements LocationListener {

                public void onLocationChanged(Location location) {
                        String message = String.format(
                                        "New Location \n Longitude: %1$s \n 
Latitude: %2$s \n Speed:
%3$s",
                                        location.getLongitude(), 
location.getLatitude(),
location.getSpeed()
                        );
                        Toast.makeText(LocationSpoofer.this, message,
Toast.LENGTH_LONG).show();
                }

                public void onStatusChanged(String s, int i, Bundle b) {
                        Toast.makeText(LocationSpoofer.this, "Provider status 
changed",
                                        Toast.LENGTH_LONG).show();
                }

                public void onProviderDisabled(String s) {
                        Toast.makeText(LocationSpoofer.this,
                                        "Provider disabled by the user. GPS 
turned off",
                                        Toast.LENGTH_LONG).show();
                }

                public void onProviderEnabled(String s) {
                        Toast.makeText(LocationSpoofer.this,
                                        "Provider enabled by the user. GPS 
turned on",
                                        Toast.LENGTH_LONG).show();
                }

        }

}

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