0

I have an Android aplication which displays a web app (of mine) into a webview. For a certain reason I want to get the device IMEI as soon as the app is open, send it with javascript from the MainActivity.java (and through the webview) to my web app (which is located in a remote server).

I have an input hidden inside the app web, and I want to give it the IMEI as value. Is that possible? Is there any way to send the IMEI through JS in the mainActivity.java to get it in the html file?

1 Answers1

0

What you can do is create a webserver on the mobile application that hosts a IMEI request api. Basically you make a simple webserver local to the application on your website you detect if the request is coming from your app typically you feed a GET variable to your site so it knows and then you activate the code that trys to run a ajax request to the local ip/port of the android device via js of course. then you submit the custom request to that url. since javascript is ran locally on a phone it can do a web request locally.

You can use this library to create a http server. https://github.com/NanoHttpd/nanohttpd

JQluv
  • 244
  • 1
  • 6
  • Wait a minute....It sounds amazing. Are you talking about hosting my website into the mere app and that host can support php files ? – Cristian Annese Jul 22 '16 at 00:46
  • Kind of i'm talking about hosting something like a request server. So website knows its on your app because the url to your site always has ?mobile=true in the url. then use your php on your website on your server to echo out some javascript code that requests to your phone locally for the IMEI. for instance the phones web address is 127.0.0.1:6843?RequestInfo=IMEI the phone responds to the ajax request and then now your website has the IMEI so you can then submit a ajax request to the php andstore it in a db or w.e but once you ask the phone for it via a webserver on the phone its all game. – JQluv Jul 22 '16 at 01:01
  • That sounds like it's the perfect solution to my problem. But the only problem is that I don't know how to do all that. I'm new at android, java, webview, etc. So it sounds so difficult to do to me. But I apreciate your answer. I'll mark it as the solution to my question ('cause actually it is), but I will need wether to learn how to do what you said or to find another way to do it. Thank you again. – Cristian Annese Jul 22 '16 at 01:17