I created a website/front-end which I also made into an Android app using Webview. I am saving some user preferences to the application using a JavaScript Interface class
@JavascriptInterface
public void sendData(String val1, String val2) {
// do something with val1 and val2
}
Then in my HTML I added the following line of code which sends val1 and val2 when a user presses the button
Android.sendData(val1,val2);
In the Android App this is working exactly how I want it to. However when using the website/front-end on a PC browser I am now getting the following error: Uncaught ReferenceError: Android is not defined
Is there a way to restrict this line of code to WebView/Mobile only? I could add a Java Script function in my HTML which would be accessed by the Android WebView app then. However, as it is now, the data is sent automatically when the user presses the button.
Thanks!