Monday, April 10, 2017

Android Webview Error I/chromium: [INFO:CONSOLE(1)] "Uncaught ReferenceError:

Leave a Comment

I have a web-service In that I have added bar-code reader for andoroid

So with the Help of JavaScript I am calling my barcode reader from webview

So for that I followed this

and designed on server side... I have Given this

at JavaScript

    function mybarcd() {            MyApp.mybarcdt();         }      function actfromAnd(msg){            document.getElementById("brcd").value = msg;        }       at HTML/PHP      <div class="data">              <input id="brcd" type="text" value=""/>             <button type="button" onClick="mybarcd()">SCAN</button>     </div> 

On Android side In webview

    webView.addJavascriptInterface(new WebAppInterface(this), "MyApp"); 

and new js interface

    @JavascriptInterface     public void mybarcdt() {                  IntentIntegrator intentIntegrator = new IntentIntegrator(Main_A.this);                 intentIntegrator.setBeepEnabled(true);                 intentIntegrator.setOrientationLocked(true);                 intentIntegrator.setPrompt("Scan Barcode");                 intentIntegrator.initiateScan();             }        @Override     protected void onActivityResult(int requestCode, int resultCode, Intent data) {         IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);         if (result != null) {             if (result.getContents() == null) {                 Log.d("ScanActivity", "Cancelled scan");                 Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();              } else {                  Log.d("ScanActivity", "Scanned");                  String bcval = result.getContents();                 if (android.os.Build.VERSION.SDK_INT < 19) {                     webView.loadUrl("javascript:actfromAnd(\""+bcval+"\")");                 }else{                     webView.evaluateJavascript("javascript:actfromAnd(\""+bcval+"\")", null);                 }                 System.out.println("javascript:actfromAnd(\""+bcval+"\")");              }         } else             super.onActivityResult(requestCode, resultCode, data);     } 

My Problem is that Its working fine in a single Html/PHP file with Js on same page or separate page I have tested its scanning and Updating the value in input box...

But its not working since I have using multiple pages or frame in one webview... its missing JS value... How ever form server its opening scanner at on-click... but after scanning the value is not passing to the input box with JS I am getting this error.....

I/chromium: [INFO:CONSOLE(1)] "Uncaught ReferenceError: actfromAnd is not defined", source:  (1) 

Update

1)I hava Tried this in Static Page with JS in side that PHP/HTML page
2)I also tried with same in a static Page with JS seperate page
On the above two conditions its worked fine

But In my webservice I have Given Same JS file which is running successfully in Static page I have a single JS file for My Webservice and Static page its working fine in static but not working in MY webservice live.. How ever JS is loading Because on click its wokring from that JS and its opening Camera But responce after scanning its not going to web input

I understand that I am getting Error Because...

In my Live Page I have a Menu Inside that menu when I select a application its loading in iframe So my Android Activity Is pinging to that menu page But for menu there is no Js function named actfromAnd So I am getting Error

Here I cant give URL of that particular page Because of depending on the menus it will change I can Give Only Login or Menus link directly.but not for a particular page inside the menu

Can Any one sugget me on this kind...

0 Answers

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment