android - Why getLastKnownLocation(provider) doesn't return null after clearTestProviderLocation(provider)


I was assuming that getLastKnownLocation does return null for a given provider after calling clearTestProviderLocation for same provider.

Why ? because documentation says for clearTestProviderLocation;

Removes any mock location associated with the given provider.

public void test() throws SecurityException {
    String provider = "TEST";
    Location location = new Location(provider);

    mLocationManager.addTestProvider(provider, false, false, 
        false, false, false ,false, false, 0, 0);

    mLocationManager.setTestProviderEnabled(provider, true);
    mLocationManager.setTestProviderLocation(provider, location);

    Location locationBefore = mLocationManager.getLastKnownLocation(provider);
    Log.d(TAG, locationBefore.toString());


    Location locationAfter = mLocationManager.getLastKnownLocation(provider);
    Log.d(TAG, locationAfter.toString());

After running test method, locationBefore and locationAfter are same!

And logs like below,

Location[TEST 0.000000,0.000000 acc=100 et=+4d10h54m26s455ms mock]
Location[TEST 0.000000,0.000000 acc=100 et=+4d10h54m26s455ms mock]

What i'm missing ?

1 Answer: 

As The documentation for getLastKnownLocation says

If the provider is currently disabled, null is returned.

you need to first disable the test provider for getLastKnownLocation to return null.


More Articles

php - Laravel openssl_private_encrypt(): key param is not a valid private key

I am trying to connect to Chef API with Laravel using PHP-Chef. I have tried to set up my chef config with the data that I got from knife.rb in .chef folder. I have setup client and a key according to the instructions from Knife.rb. But I get:openssl_private_encrypt(): key param is not a valid priva

android - Mock location not working on Google map

I have used code from this. I have changed it a bit. Below is my code snippet. The problem is Google Map is not showing proper location which i have mocked.public class MockGpsProviderActivity extends Activity implements LocationListener {public static final String LOG_TAG = "MockGpsProviderActivity

git - How to use libgit2sharp with ssh-transport-protocol?

When I use libgit2sharp in project to clone repository with ssh-transport protocol, like It throw an exception, says "This transport isn't implemented. Sorry"How can I clone repository with ssh-transport-protocol by using libgit2sharp ?

C# HMAC SHA-256-128 Calculation result not as expected

I'm trying to create a signature to our bank from a specified key but my results is not the same as the info I got from the bank. Can anyone see what I am doing wrong?Link to bank for reference (text in Swedish)Example data are inside the citationmarks .. :)Filedata: "00000000"Key:

openssl - Send Push with .p8 and PHP

I need to send Push notifications through PHP script by using .p8 file and found following code in similar question asked here.<?php $keyfile = 'AuthKey_AABBCC1234.p8'; # <- Your AuthKey file $keyid = 'AABBCC1234'; # <- Your Key ID $teamid = 'AB12

android - Mock Location permission issue on release app

I developed Fake GPS application and all my codes work nicely on debug mode.When i try "mock location" on **release version**, i got this error;java.lang.SecurityException: Requires `ACCESS_MOCK_LOCATION` permissionI already had ACCESS_MOCK_LOCATION in debug/AndroidManifest file.<uses-permission

regex - Regular expressions in R: pattern repetitions with {}

I am having trouble with a regular expression in R. The goal is to parse a Markdown/reST/knitr report text file in R to remove my own custom comments. These comments are put in the following form: Some sentence is about something <find a citation to this>.As Markdown uses <> for HTML tags,

cmake - How to build openCV 3.3.0 with GStreamer on Windows

Having Gstreamer 1.22 successfully installed I'm not able to configure the project to build OpenCV. CMake isn't able to find GStreamer on my machine. Any ideas how two address this issue?

sql server - How to add Text at the end of each line

I'm developing a program with VB.NET (2013), which works with a local database (sql server 2008 R2),The program is converting database tables into text files ,so how to add some text after the last field of each row at the end of each line in that text file,Thanks, And sorry for my englishIf mytable

c++11 - C++ problem with understanding of counting char variables

I wrote a program that supposed to print the number of characters that i entered till it hits the '#' character. what i don't understand is, when i input in the console more than one character (say "hello world") the program count all the characters in one iteration. why does it count all the charac