1

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!

1 Answer 1

1

I amended the HTML/JS line as follows:

try{
Android.sendData(val1,val2);
}
catch(e) {
//
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.