Android Question ALLOW_MOCK_LOCATION

D

Deleted member 103

Guest
Hi,

Is there no way to know that this option is enabled?

 
D

Deleted member 103

Guest
Thank you Erel,

I have found a solution.
B4X:
Public Sub isLocationFromMockProvider(location1 As Location) As Boolean
    return nativeMe.RunMethod("isLocationFromMockProvider", Array(GetContext, location1))
End Sub

#Region Subs für Mocklocation
#If JAVA
import android.provider.Settings;
import android.provider.Settings.Secure;
import android.content.Context;
import android.test.mock.MockContext;
import android.location.Location;

public static boolean isLocationFromMockProvider(Context context, Location location) {
    boolean isMock = false;
    if (android.os.Build.VERSION.SDK_INT >= 23) {
        isMock = location.isFromMockProvider();
        return isMock;
    } else {
        if (Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION).equals("0"))
            return false;
        else {
            return true;
        }
    } 
}
#End If

Private Sub GetContext As JavaObject
    Return GetBA.GetField("context")
End Sub

Private Sub GetBA As JavaObject
    Dim jo As JavaObject
    Dim cls As String = Me
    cls = cls.SubString("class ".Length)
    jo.InitializeStatic(cls)
    Return jo.GetFieldJO("processBA")
End Sub
 
Upvote 0
D

Deleted member 103

Guest
Hi,
Unfortunately, this does not work anymore, when compiling comes this error message.
Does anyone know a solution?

 
Upvote 0
D

Deleted member 103

Guest
Doesn't look like your code is using this import at all. Just delete that line.
If I delete this line then the app crashes with this error message.

Last working version was with B4a 7.81 and android-sdk 26.
If there is no solution, then I have to remove the function.
 
Last edited by a moderator:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…