Mock location does not work in Android Studio Emul

2019-09-11 02:04发布

问题:

From reading this guide, I tried to send gps location to the emulator, but it doesn't work. I tried with Google Maps. The emulator info: Nexus 5, API Level 19, Kitkat 4.4

A screen shot: (click send but nothing happens)

回答1:

You can use mock location in your app, I don't think it will work google maps as it won't have permission to use mock location. You have to declare android.permission.ACCESS_MOCK_LOCATION in manifest.

Get the location using

LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        if (locationManager.isProviderEnabled(GPS_MOCK_PROVIDER)) {
            locationManager.requestLocationUpdates(GPS_MOCK_PROVIDER, 0, 0f, this);
        }