Search code examples
javascriptjavaandroidwebviewimei

Get device IMEI and send it through WebView to a website


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?


Solution

  • 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