Java Question Converting AndroidUSBCamera to B4A

Status
Not open for further replies.

Alessandra Pellegri

Active Member
Licensed User
Longtime User
I am trying to convert this library to mke USB Camera working on B4a.

https://github.com/suethan/AndroidUSBCamera/blob/master/README.md

I am using SimpleLibraryCompiler tool, I modified the original library because as is it doesn't compile with this tool.

Now; if I compile the library without wrapper it compiles without errors (except for warnings ShortName missing).

I tried to create the wrapper:
B4X:
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.DependsOn;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
import anywheresoftware.b4a.keywords.Common;
import com.dreamguard.api.USBCamera;

import android.content.Context;
import android.graphics.SurfaceTexture;
import android.hardware.usb.UsbDevice;
import android.util.Log;
import android.view.Surface;
import android.widget.Toast;

import com.dreamguard.usb.camera.CameraHandler;
import com.dreamguard.usb.detect.DeviceFilter;
import com.dreamguard.usb.detect.USBMonitor;
import com.dreamguard.usb.detect.USBStatus;

@Author("Suethan")
@Version(1.0f)
@ShortName("USBCamera")
public class USBCameraWrapper {
   public void init(Context context) {
       USBCamera.init(context);
   }
    }
but because I am not a Jva expert I have this error:
B4X:
Starting step: Compiling Java code.
javac 1.8.0_65
C:\Users\Tommaso\Desktop\CameraUSB\ee\src\main\java\com\dreamguard\USBCameraWrapper.java:26: error: non-static method init(Context) cannot be referenced from a static context
       USBCamera.init(context);
                ^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: C:\Users\Tommaso\Desktop\CameraUSB\ee\src\main\java\com\dreamguard\renderer\RenderHandler.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error


Error.

Could you help me ?

Thank you

Here the files:
B4X:
AndroidUSBCamera-masterModifiedB4A https://drive.google.com/open?id=1abAFBU4_m3fT_1IHM1kmJejUJ0QjeYoY
AndroidUSBCamera-masterOriginal https://drive.google.com/open?id=1PEsiuj_XMLvEqEJp66y6mukHCkvGU91c
 

Alessandra Pellegri

Active Member
Licensed User
Longtime User
Now it compiles, but when I load libraries into B4A I obtain errors like this:
B4X:
An error occurred.
Error parsing libraries.
com.dreamguard.widget.UVCCameraTextureView.HasTransient hastransientstate already exists.
 

Alessandra Pellegri

Active Member
Licensed User
Longtime User
OK, works.

Now when I try to compile this code:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   'Activity.LoadLayout("Layout1")
   Dim hh As USBCamera
   hh.init(GetContext)
End Sub

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

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

I obtain this error:
B4X:
B4A version: 6.80
Parsing code.    (0.00s)
Compiling code.    (0.02s)
Compiling layouts code.    (0.00s)
Organizing libraries.    (0.00s)
Generating R file.    (0.05s)
Compiling generated Java code.    Error
javac 1.8.0_65
src\b4a\example\main.java:331: error: cannot find symbol
USBCameraWrapper _hh = null;
^
  symbol:   class USBCameraWrapper
  location: class main
Note: src\b4a\example\starter.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error
 

Alessandra Pellegri

Active Member
Licensed User
Longtime User
Solved, I had to add
B4X:
package anywheresoftware.b4a.objects;
at the top of the wrapper
 
Last edited:

marcos_sa

Member
Solved, I had to add
B4X:
package anywheresoftware.b4a.objects;
at the top of the wrapper
Alessandra, is your lib 100% functional? I do need something like this and if it is fully tested and consistent I could buy it as long as you provide me with a sample code as well. Waiting for you.
 

mjcoon

Well-Known Member
Licensed User
Alessandra, is your lib 100% functional? I do need something like this and if it is fully tested and consistent I could buy it as long as you provide me with a sample code as well. Waiting for you.
Did you get a response? I am a bit puzzled there was no mention in the discussion about having to set "OTG" permission/setting. This is because I thought it was for "host" usage of USB.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…