Android Question web to app communication - Intentservice

brampie66

Member
Licensed User
Longtime User
Hi,

I need to print some labels from a web application (chrome on android).
On PC I use a small webserver application and XmlHTTPRequest to send printer data (ZPL for example) to the serial or usb port.

On android I would have done the same but it seems like a HTTPS server is not yet possible with b4a,
plain http is often not allowed in this case because the web app itself is https.

So I use an Intent, this works fine (myapp://printlabel?id=111) but after printing my app stays in the foreground, when I run Activity.Finish in the end the app stops receiving these intents.
I tried redirecting this intent to a service but this doesn't seem to work (can't cast service to Activity).

So,I have two questions:
-Is an https server indeed not yet possible in B4A ? This worked very well actually (tried it with http).

-Is there another a way to hide but not finish my activity and return to the browser window where the link was clicked.
Or get the intent sent to a service.

-This seems to be what I need, https://developer.android.com/reference/android/app/IntentService
but it's unclear to me how to make that work in B4A, esp the manifest part.

Does anyone have some pointers ?

thx
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
IntentService is not related.

Sending an intent to your app is a much better option then building a http server.
The HttpServer library doesn't support SSL connections.

when I run Activity.Finish in the end the app stops receiving these intents.
What happens if you refresh the web page? It sounds like a browser issue.
 
Upvote 0

brampie66

Member
Licensed User
Longtime User
Hi,

Thanks for your response.

Makes no difference once my app is not "running" any more (I called finish on the last visible activity) I get no Intents (despite the fact that this same app has an unrelated foreground service running).
Refreshing or stopping the browser does not help.

Doesn't IntentService allow for such an Intent to be sent to a service ? (Or it's not meant to be used in that way)

Is there a plan to add SSL to HTTPServer ? I could use http and see if I can force the browser to allow mixed content for now.
HTTP(S) allows an easy way to communicate both ways, I can then also use the same web code for android and the pc.
HTTP worked a lot faster than intents do.

An alternate solution I've been thinking about is just listening an a port (serversocket), sending a https request to that port (it will fail but that's not really such a huge problem) and simply use the "new connection" event as a trigger to check for new tasks (wich I would then store on the server in a queue).
This is however a fairly complicated solution, still it seems doable, I think I could include data as a subdomain and SNI would allow you to read that part without SSL, https://label123.mylocalhost.com , using a wildcard dns (not sure it this would work, but in this case I won't need a server based queue)

thx
 
Upvote 0

brampie66

Member
Licensed User
Longtime User
I think I can solve this.
-Mixed content to localhost does seem to work on recent android chrome versions, so HTTP is fine
-Using a socketserver and a wildcard domain also works.

thx
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…