thanks but I can not receive it as I do in the java code?B4X:NativeMe.Runmethod("methodName",Array("String1","String2"))
thanks but I can not receive it as I do in the java code?B4X:NativeMe.Runmethod("methodName",Array("String1","String2"))
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim NativeMe As JavaObject
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
NativeMe.InitializeContext
NativeMe.Runmethod("methodName",Array("String1","String2"))
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
#If java
public void methodName(String s1,String s2){
BA.Log(s1 + " " + s2);
}
#End If
Hello Erel,It depends on the complexity of the wrapped library. However you can add a reference to the library with #AdditionalJar attribute and then use inline Java code or JavaObject to access its API.
See this tutorial: Accesing third party Jar with #Additionaljar and JavaObject
I'll start experimenting with OpenCV following this road.You can add any Java you like. However if you are not familiar with Java then it will be difficult to use this feature with non-simple code.
To be or not to be (..the right file..) that is the question!You need to check their documentation. Is this the jar you need to add to your Android project?
#If JAVA
import java.lang.Math;
import java.lang.Float;
public class AquaLib {
public Float one(Float kh,Float co) {
float x = (float) Math.round((7.90+Math.log(kh/(2.8*co))/Math.log(10))*100)/100;
return x;
}
public Float two(Float kh,Float co) {
float x = (float) Math.round((7.90+Math.log(kh/(2.8*co))/Math.log(10))*100)/100;
return x;
}
public Float tree(Float kh,Float co) {
float x = (float) Math.round((7.90+Math.log(kh/(2.8*co))/Math.log(10))*100)/100;
return x;
}
public Float four(Float kh,Float co) {
float x = (float) Math.round((7.90+Math.log(kh/(2.8*co))/Math.log(10))*100)/100;
return x;
}
}
#end if
NativeMe.InitializeStatic("AquaLib")
Dim s As Float = NativeMe.RunMethod("one",Array As Object(kh,co))
Sub Process_Globals
Private nativeMe As JavaObject
End Sub
Sub Service_Create
nativeMe.InitializeContext
End Sub
Sub Service_Start (StartingIntent As Intent)
Dim l As Long
l = nativeMe.RunMethod("FreeSpace", Array(File.DirRootExternal))
Log("l = " & l)
End Sub
#If JAVA
import java.io.File;
import android.content.Context;
public long FreeSpace(String Pathf) {
File f = null;
long v;
boolean bool = false;
try{
// create new file
f = new File(Pathf);
// get number of unallocated bytes
v = f.getFreeSpace();
// true if the file path exists
bool = f.exists();
// if file exists
if(bool)
{
// prints
return v;
}
else
{
return 0;
}
}catch(Exception e){
// if any error occurs
return 0;
}
}
#End If
** Service (serverservice) Create **
Error occurred on line: 40 (serverservice)
java.lang.NoSuchFieldException: context
at java.lang.ClassCache.findFieldByName(ClassCache.java:446)
at java.lang.Class.getDeclaredField(Class.java:666)
at anywheresoftware.b4j.object.JavaObject.InitializeContext(JavaObject.java:64)
at mlc.wifitransfer.serverservice._service_create(serverservice.java:6308)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:302)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at mlc.wifitransfer.serverservice.onCreate(serverservice.java:48)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:1949)
at android.app.ActivityThread.access$2500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:989)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3691)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670)
at dalvik.system.NativeStart.main(Native Method)
** Service (serverservice) Start **