Android Question Searching for KSWEB-Control for B4A

DonManfred

Expert
Licensed User
Longtime User
Hallo,

i´m using KSWEB to have MySQL, PHP, Webserver running on my Device. BUT i don´t want to have all of them running all the time. My goal is to start server(s) when my App is started. The Authors of KSWEB publishes a java-Class which should be included with the activity. See KSWEBControl.java.txt (changd ext to .txt to be able to upload here)

Is someone here able to make a library out of it? I would really appreciate any help in this...
I´m disposed to give a donation for it...


They published a blog about this class here:

KSWEB Control
You can control KSWEB by your application via Android Broadcast messages. Note that this feature is in beta testing at the moment and this is the first version of it. List of commands will be changed and be refined over time.

To apply control commands use this java class in your Android project: KSWEBControl.java
The typical usage is to extend this class by your main activity. Each command requires a tag for tracking of the result of its execution. KSWEB sends an answer with a tag via Broadcast after executing any command. It can be KSWEBControl.RESPOND_OK or KSWEBControl.RESPOND_ERROR.

Here you can see a list of available commands to control KSWEB.

This group of static commands allows you to start/stop components (servers) of KSWEB

public static void ftpStart(Activity activity, String tag);
public static void ftpStop(Activity activity, String tag);

public static void lighttpdStart(Activity activity, String tag);
public static void lighttpdStop(Activity activity, String tag);

public static void nginxStart(Activity activity, String tag);
public static void nginxStop(Activity activity, String tag);

public static void mysqlStart(Activity activity, String tag);
public static void mysqlStop(Activity activity, String tag);

These commands allow to start/close KSWEB. “Finish activity” allows to unload KSWEB from memory without shutting down servers

public static void kswebStart(Activity activity, String tag);
public static void kswebClose(Activity activity, String tag);
public static void kswebFinishActivity(Activity activity, String tag);

To configure servers use these commands

Content of configuration file will be replaced by data from configTxt parameter.

public static void lighttpdSetConfig(Activity activity, String tag, String configTxt);
public static void nginxSetConfig(Activity activity, String tag, String configTxt);
public static void phpSetConfig(Activity activity, String tag, String configTxt);
public static void mysqlSetConfig(Activity activity, String tag, String configTxt);


To control http servers host list you can use these commands

public static void lighttpdAddHost(Activity activity, String tag, String hostname, String port, String rootDir);
public static void lighttpdDeleteHost(Activity activity, String tag, String hostname, String port, String rootDir);


public static void nginxAddHost(Activity activity, String tag, String hostname, String port, String rootDir);
public static void nginxDeleteHost(Activity activity, String tag, String hostname, String port, String rootDir);
 

Attachments

  • KSWEBControl.java.txt
    7.7 KB · Views: 254
Last edited:

barx

Well-Known Member
Licensed User
Longtime User
Looking at it, it seems simple enough to make into a lib. I would have a crack at it if I had more time today, but I am laying new floor in bathroom. If no one has helped out later, I will see if I can get some time. Sorry

Also, I think you should just be able to write the intents in b4a anyway. Use broadcast receiver lib. The text file show what the constant values are, so define a set of vars in b4a with those values.

Then just create an intent for each command using the constants.

Keep us updated and like I say, I will try to help more later, time permitting.

Good luck
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User

I thought similar after looking at the javacode... But i´m not sure how such an intent shoulld look like in b4a-codes... I´ll have a look at the broadcaster thing you told about later... must go shopping something to eat

Anyway thank you for your answer! Really appreciated! I´ll keep this thread updated
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Well off the top of my head, and not including the broadcastreceiver (which appears to be used to get a response of if the command was successful)

Declare Constants (Not really constants in B4a but serve their purpose)
B4X:
Dim FTP_START as String = "ru.kslabs.ksweb.CMD.FTP_START"
Dim FTP_STOP as String = "ru.kslabs.ksweb.CMD.FTP_STOP"
.....
.....
Dim TAG_KEY as String = "TAG"

The create a new sub for each command

B4X:
Sub FtpStart(Tag as String)
    Dim I as Intent
    I.Initialize()
    I.Action = FTP_START
    I.PutExtra(TAG_KEY, Tag)
    StartActivity(I)
End Sub

I'm not great with intents in b4a but it shouldn't be far off. I'm sure someone else will correct me if wrong.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User

Initialize needs parameters... I´ve tried it with
B4X:
    Dim I As Intent
    I.Initialize("","")
        I.Action = FTP_START
    I.PutExtra(TAG_KEY, Tag)
    StartActivity(I)
but run into i´ve tried other variant too but mostly i run into this error too. In one case i´ve started the ksweb-app (ru.kslabs.ksweb) but then i need to exit the app and do all manually...

I can´t get it to run as i´m a noob about intents :-/

Maybe you found a little bit time when you Bathroom floor is ready...
Hopefully it´s a "normal floor" and not like a street painting

 
Upvote 0

keirS

Well-Known Member
Licensed User
Longtime User
Try this.

B4X:
Dim i As Intent
    i.Initialize("ru.kslabs.ksweb.CMD.FTP_START,"")
    i.PutExtra("TAG","FTP1")
    StartActivity(i)

I think you may need to start the KSWEB app with the given intent first. Also you will need to use the BroadcastReciver library as KSWEB responds with success or failure intents using the string you pass as the tag value.
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
did you get this working ?
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
I will install the app once get to work and try have a little play at some point today. Hopefully have a solution for you later today.
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
I have just written a library for this and upon testing I get pretty much the same error. So wondering if the implementation on their side is balls up. been looking for an .apk to decompile in order to check out the manifest for clues....
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
OK, I seem to have the commands working. just not the response.......

getting there

The reason the Activity error is being given is because the server app has to be running in the background. The receiver for these commands are dynamic, not static in the manifest. Kinda makes sense I suppose......
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
I think it is all done now mate, just driving home from work. I will post the tester up for you later on this evening. Probably about 3 hours time. Then you see if the implementation is good for you.
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Try this @DonManfred

Extract and copy .jar and .xml to additional libs folder as usual.

Check out the demo app for usage.

Hope it works, good luck
 

Attachments

  • KSWebControllerDemo.zip
    7.2 KB · Views: 172
  • KSWebControl.zip
    5 KB · Views: 175
Upvote 0

DonManfred

Expert
Licensed User
Longtime User

will do... great

Extract and copy .jar and .xml to additional libs folder as usual.
done

Check out the demo app for usage.

done. looks good

Hope it works, good luck

Sadly it does nothing.
The ksweb-app (fullversion) is running in background.
I can click on the toggle-button in your demo-code after compiling with b4a 3.82 but nothing happens. No log-output, no error.
But the ftp would not be started if i switch to kswebapp to see the status.

I´ve compiled with rapid debugger... Will try another dbugger

Edit: the same with normal debugger.
No log-output. No error. But also no success too
 
Last edited:
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
hmmmm, I will double check it. It worked for me. but I only used the trial. Does the full version have same package names?

Also, When I activated the toggle and then went back to KSWeb, no change on status. BUT if you swipe to another page in the app, then back it updates the status with new value
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Also, double check the KSWeb app first. Sometimes I was unable to manually turn things on / off. Seemed to me if http server was off, none of others could be enabled.
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Ok here it seems to work, but the server app is sketchy. If it is not working, check the server app and see if you can manually stop / start the server, everytime it that it control app doesn't work here the server app toggles seem to be disabled. Maybe that is me switching too fast. If I tap the X in top corner of server app it seems to restart the servers and then the controller app works again.
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Oh and re register the receiver on resume with ks.register or was it registerReceiver. Lol, you'll see what I'm in about. Pc is off for the night now. I will pick up in the morning.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Oh and re register the receiver on resume with ks.register or was it registerReceiver. Lol, you'll see what I'm in about.

i already found the "missing" re-register by myself and put a ks.register in activity_resume... Could be great if the lib supports a status for register... maybe
B4X:
if ks.IsRegistered = false then
  ks.register
end if

I´ll do more checks this evening... Have to go to work in a few minutes.

Anyway: i would like to say out a big THANK YOU for your work, your example and your anwers here! Really great. It´s 100% appreciated
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…