0

I wish to create a web interface for my android application wherein the user can connect using WiFi and do "stuff" similar to the web interfaces provided by many file sharing services like Xender.

Xender Web interface

I am using nanohttpd to host the web interface. I wish to call a function when a user presses a button on the web page (for example to turn on the flash light).

When the application is opened it starts the server and listens on a particular port. The web interface basically consists of a button. A user can log into the web interface and press the button to turn on the flash light. For that I need the android code to be called when the user presses the button.

How can I accomplish this? Are there better alternatives?

YakovL
  • 7,557
  • 12
  • 62
  • 102
Ray
  • 293
  • 1
  • 3
  • 12
  • So the page ( static or dynamic? ) is served by nanohttpd. And who is displaying it? And where? You should tell much more of your setup. – greenapps Feb 05 '16 at 07:02
  • @greenapps I have updated the question details. I am not sure how to implement this. But the requirement is similar to the web interface provided by file sharing applications like Xender. – Ray Feb 05 '16 at 07:38
  • I do not know Xender. You did not answer my question who is displaying the web page.And other questions. Your description is still very vague and confusing. For instance: `When the application is opened it starts the server and listens on a particular port`. You mean that your app will start nanohttpd? Ok. And your app listens on a specific port? Is your app a server too? For what? – greenapps Feb 05 '16 at 07:44

1 Answers1

0

This answer is late but adding in case someone reach to this page and still looking for the answer.
If a browser would be used to access the web page from nanoHttpd server there is no easy way to call the native APIs as mentioned in the answer here.
Instead a web view can be used to render the page and then the native APIs can be used using addJavascriptInterface as mentioned here.
Also frameworks like PhoneGap or Cordova can be used to get the specific functionality already built in as a plugin to use. Check this PhoneGap plugin for flashlight here.
Although if opening page in a browser is a requirement, you can also use Android Intents with chrome to launch a service application which will call the required native APIs.

Rishabh Agrawal
  • 122
  • 1
  • 8