Converting USB Library have Context issue.

mleffler

Member
Licensed User
Longtime User
I'm converting a .jar file for SlickUSBLibrary to Basic4Android.
F.Y.I it allows an Android device to read from or write to a device attached to the USB port.

So far the conversion has been a pain but it looks like it is mostly done.

One last issue is that the library uses "android.content.context" and I cant seem to figure out how to convert that for Basic4Android.
I have seen a couple of posts about this subject but so far have not seen an answer.

Anyone have any ideas on how I can do the conversion?

thanks,
 

moster67

Expert
Licensed User
Longtime User
I can't really explain (very poor java-knowledge) but here is a library I wrote sometime ago which uses "android.content.Context".

For more specific questions, you need to ask the gurus but perhaps the code might help you nonetheless:

B4X:
package tillekesoft.b4a.ToggleWifiData;

import android.net.wifi.WifiManager;
import android.content.Context;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ActivityObject;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.Version;


@ShortName("ToggleWifiData")
@Permissions(values={"android.permission.CHANGE_WIFI_STATE", "android.permission.ACCESS_WIFI_STATE","android.permission.UPDATE_DEVICE_STATS","android.permission.MODIFY_PHONE_STATE"})
@Author("Moster67")
@Version(1.0f)

public class ToggleWifiData  {
    
     private BA ba;

      public void Initialize(BA ba)
      {
        this.ba = ba;
      }
    
public boolean isWIFI_enabled()
{
    WifiManager wifiManager = (WifiManager) this.ba.context.getSystemService(Context.WIFI_SERVICE);
      
    if(wifiManager.isWifiEnabled()){
        return true;
    }else{    
        return false;
    }
}      
      
public boolean toggleWIFI()
{
    WifiManager wifiManager = (WifiManager) this.ba.context.getSystemService(Context.WIFI_SERVICE);
    
    if(wifiManager.isWifiEnabled()){
        if(wifiManager.setWifiEnabled(false))
            return true;
      }else{
        if(wifiManager.setWifiEnabled(true))
            return true;
    }
    return false;    
}

}
 
Upvote 0

JoanRPM

Active Member
Licensed User
Longtime User
Sorry, I can not help you, but I am very interesting on this.
I have also tried using the USB port to communicate in any simple way, but I have not succeeded. I have watched some kits (Microchip Android Kit, Elektor, ...) but all are based on android slave port. They also use libraries that do not know how to adapt to B4A.
If you make any progress, please, let us know.
Greetings.
 
Upvote 0

mleffler

Member
Licensed User
Longtime User
Progress so far

I started to convert the SlickUSB library to Basic4Android.
I have created the .jar and .xml files but there is still some issue. It does not work correctly.
I have been pulled off to other things so I dont know when I will get back to it.

I'll post what I have here for now and if someone wants to continue with it just post the complete files and let everyone know.

You will need to purchase SlickUSBLibary to use this of course.
I have run the sample programs on my tablet and they do work with the USB port correctly the library is just not setup for Basic4Android.
 

Attachments

  • SlickUSBLibrary.zip
    45.3 KB · Views: 240
Upvote 0

JoanRPM

Active Member
Licensed User
Longtime User
Mleffler, thank you very much.

I do not know anything about Java and now I have little time to devote.

At work, I need the USB port to make an application and for now I opted for a choice of FTDI (VNC2) that I know it works (someone on the forum already has).
I have the evaluation board, but I have not yet started.

In the future I would like to adapt the evaluation board from Microchip, which also I have it and works very well.

Greetings.
 
Upvote 0
Top