Questions tagged [android-jsinterface]

Android's `JavascriptInterface` is an interface that allows calling of native (Java) code from an embedded Webkit Webview. Security precautions should be taken to ensure that only your own pages will run in the webview, or that all Java code that can be called will not cause a security breach.

Android's JavascriptInterface is an interface that allows calling of native (Java) code from an embedded Webkit Webview. Security precautions should be taken to ensure that only your own pages will run in the webview, or that all Java code that can be called will not cause a security breach.

Official documentation: https://developer.android.com/guide/webapps/webview.html#AddingWebView

34 questions
24
votes
4 answers

Sometimes throws Uncaught Error: Error calling method on NPObject on Android

I am having problems with the Webview in Android and it's JavascriptInterfaces. I am passing a string to the JavascriptInterface. When debugging it, I receive the correct string within my Android application. The problem: Sometimes I get an Uncaught…
janwo
  • 754
  • 2
  • 8
  • 17
3
votes
0 answers

Listening to window events within Android WebView

I'm loading a webpage within a WebView and trying to subscribe to JS events. As an example, let's say I'm looking for the window 'load' event. I configure the webview in its…
siger
  • 3,112
  • 1
  • 27
  • 42
3
votes
1 answer

Call C# method with parameter from JS xamarin

I tried to call C# method from JS with arguments, but I've got an error. I'm using Xamarin Android (not Xamarin.Forms) C# Code: [JavascriptInterface] [Export("test")] public Java.Lang.String Test(Java.Lang.String hello) { return hello; } JS…
suhotrub
  • 118
  • 1
  • 7
3
votes
3 answers

Android: how to initiate android's featues through javascript

I have a code to speak a text passed from html. Which I was able to make it working using below code. Here is the code: tts = new TextToSpeech(this, this); myWebView = (WebView) findViewById(R.id.webviewid); //The html text is from the…
User12111111
  • 1,179
  • 1
  • 19
  • 41
3
votes
1 answer

Android: how to load local javascript file to WebView

I am trying to write a program which does a simple toast. When I tried adding the script within the HTML, it worked and am able to see the toast. But when I placed the same script code in separate file under assert folder(script.js), it fails to…
3
votes
1 answer

Javascript Interface, error "Uncaught Error: Error calling method on NPObject"

In my Android application, I am using the WebAppInterface to bridge from Javascript to Java. My .html file includes some JS that runs "Android.canPlay();" at certain times. In my app, the function "canPlay()" fires a variable listener. When the…
3
votes
0 answers

Android 4.4 : Unable to call Java method from Java script

I am trying to make a call a method in my activity from java script using This works fine on 4.1.2 JB, but not working on 4.4 Kitkat, Any idea, how to solve this?
Code_Yoga
  • 2,968
  • 6
  • 30
  • 49
3
votes
0 answers

Using WebView for multi-page login to website and fetch data

I'm building an Android app as a mobile client for a website that does not (and will not) have it's own UI for mobile browsers. My chosen architecture uses a hidden WebView which I initialise (loadURL) with the login page, and then I load…
DaveF
  • 31
  • 3
2
votes
1 answer

Android Webview JSInterface communicate with ReactJS

Is there any way, how the Web application, that was purely written in ReactJS, could communicate with the Android native application, that contains only webview, where I'm loading this ReactJS application? I couldn't rewrite the ReactJS app to React…
jantursky
  • 1,122
  • 1
  • 10
  • 21
2
votes
1 answer

Android webview javascript Interface not working properly

Really do not have any ideal why this doesn't work. Basically, I am trying to do this. public void testJS() { final WebView webView = (WebView) findViewById(web); // webView.getSettings().setDomStorageEnabled(true); …
Belvi Nosakhare
  • 3,107
  • 5
  • 32
  • 65
2
votes
2 answers

android.view.InflateException:Binary xml file Error inflating class org.xwalk.core.Xwalkview

I am trying to build hybrid app using xwalkview but continuosly getting this error. I have added crosswalk-webview-arm library and appcompat-v7 libarary and 2 jars. android-support-v4 jar and xwalk-core-library.jar. Removing any one of them is…
SwagDevelopers
  • 109
  • 2
  • 12
2
votes
0 answers

android native and javascript communication in browsing a file from device

I have opened html page in webview. Now on click of any button in the webview, I want user to pick an image from gallery and show that image in webview. Code in onCreate() method: myBrowser = (WebView)findViewById(R.id.webView1); …
Kanika
  • 10,648
  • 18
  • 61
  • 81
2
votes
2 answers

How to pass a Javascript function as an argument in Javascript Interface?

How to pass a function as a parameter in Javascript Interface, save it as a string and then call? For example, I describe the Javascript Interface: class JSInterface{ String myFunction; //set function into myFunction attribute …
Oleg_Korchickiy
  • 298
  • 5
  • 15
2
votes
0 answers

Inspect element for html loaded in android application

I am rendering an html file using webview in my Android application. I am also using some javascript functions to handle the contents. Is there any way to inspect the html content (like the inspect element in the browser ) Please help, Thanks in…
Jithu.S
  • 88
  • 1
  • 7
2
votes
1 answer

Ajax request support Android

Is Ajax Request supported in android(4.0 +). If so please provide some help. I need to call ajax from android WebView using javascript.
Jithu.S
  • 88
  • 1
  • 7
1
2 3