Android Question Funcion JAVA in B4X . Where put or call (SOLVED; OBJECT=ME)

netsistemas

Active Member
Licensed User
Longtime User
I'm trying this error message:
java.lang.RuntimeException: Method: isMockLocationOn not found in: android.app.Application

I try the function that gives an error in the STARTER service and that is where I use it.

What could be wrong?
This is my code inside the STARTER


(


B4X:
Sub Process_Globals
   Dim JavaObject2 As JavaObject
End Sub

'.... init flp etc..

Private Sub flp_LocationChanged (Location1 As Location)

    Try
            'IsFake = JavaObject2.RunMethod("isMockLocationOn", Array(Location1))
            IsMockLocationMio(Location1)

    Catch
        Log(LastException)
    End Try

End Sub




public Sub IsMockLocationMio (Location1 As Location)
'ESTO NO FUNCIONA, pero isMockLocationOn sí, pero da error pues no detecta la función
'this not work, but isMockLocation is ok, but not work. funcion java are not detectec
'    Dim p As Phone
'    modGPStoy.IsFake=  IIf(p.GetSettings("mock_location") = "0" ,False ,True)
   
    JavaObject2.InitializeContext
    modGPStoy.IsFake = JavaObject2.RunMethod("isMockLocationOn", Array(Location1))
End Sub




#If JAVA
import android.app.Service;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.PowerManager;

import android.provider.Settings;
import android.provider.Settings.Secure;
//import android.test.mock.MockContext;
import android.location.Location;

public boolean isMockLocationOn(Location location) {
    Context context=this;
   boolean isMock = false;
    if (android.os.Build.VERSION.SDK_INT >= 18) {
        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
 
Last edited:

netsistemas

Active Member
Licensed User
Longtime User
thank...
(tag: ismocklocation , java.lang.IllegalArgumentException: Expected receiver of type , java.lang.RuntimeException: Cannot parse: (Boolean) true as boolean
solved
with JavaObject2= me


and other problem about:
java.lang.IllegalArgumentException: Expected receiver of type factunet.crm.starter, but got java.lang.Class<factunet.crm.starter>

(comment in code)

B4X:
public Sub IsMockLocationMio (Location1 As Location)

    'Dim p As Phone
    'modGPStoy.IsFake=  IIf(p.GetSettings("mock_location") = "0" ,False ,True)

    'solution for:
    'java.lang.IllegalArgumentException: Expected receiver of type factunet.crm.starter, but got java.lang.Class<factunet.crm.starter>
    'in https://www.b4x.com/android/forum/threads/using-external-jar-lib.110501/
    
    JavaObject2.InitializeNewInstance("factunet.crm.starter",Null)
    Dim X As String
'problem: java.lang.RuntimeException: Cannot parse: (Boolean) true as boolean
    x = JavaObject2.RunMethodJO ("isMockLocationOn", Array(Location1))
    If x.Contains("true") Then
        modGPStoy.IsFake =True
    Else
        modGPStoy.IsFake =False
    End If
    
End Sub

for me the solution was:
JavaObject2.InitializeNewInstance("factunet.crm.starter",Null)

and get boolean in string (3 problemas in 1 method!!!)
 
Upvote 0
Top