Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7803863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:43:26+00:00 2026-06-02T01:43:26+00:00

I am new to Android and was trying to setup the Android Webview to

  • 0

I am new to Android and was trying to setup the Android Webview to load a javascript function and return the result to a callback function.

See the code below

public class AWebViewActivity extends Activity {

    /**
     * Defines an Interface to call Syntax Highlighting Javascript and return the result
     * to a string by calling the call back function.
     */
     public class JavaScriptInterface {
         Context mContext;
         JavaScriptInterface(Context c) {
             mContext = c;
         }

         //add other interface methods to be called from JavaScript
         // This annotation is required in Jelly Bean and later:
         @JavascriptInterface
         public void receiveValueFromJs(String str) {
              //do something useful with str
              Toast.makeText(mContext, "Received Value from JS: " + str,Toast.LENGTH_LONG).show();
         }
    }

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // Try WebView
        WebView webView = (WebView) findViewById(R.id.editor_view);
        //webView.setWebChromeClient(new WebChromeClient());

        webView.getSettings().setJavaScriptEnabled(true);

        // RiNxX's suggestion
        webView.setWebViewClient(new WebViewClient(){
            @Override
            public void onPageFinished(WebView view, String url){
                view.loadUrl("javascript:getValue()");
            }
        });

        webView.addJavascriptInterface(new JavaScriptInterface(this), "MyAndroid");
        webView.loadUrl("file:///mnt/sdcard/a.html");

        //SystemClock.sleep(1000);
        //webView.loadUrl("javascript:getValue()");
    }
}

The HTML file is given below:

<html>
    <head>
    </head>
    <body>
        <script type="text/javascript">
            function getValue()
            {
                var val="Amith Raravi";
                MyAndroid.receiveValueFromJs(val);
            }
        </script>
    Hey ya
    </body>
</html>

I have also added the INTERNET permission as a child of the Manifest element. I went through the other questions posted on StackOverflow and moved the script to Body of the HTML.

After i added the changes suggested by RiNxX, the app closes(it doesnt execute the callback) and i get the below warning in LogCat

JNI WARNING: jarray 0x405414e8 points to non-array object (Ljava/lang/String;)
I/dalvikvm(361): "WebViewCoreThread" prio=5 tid=9 NATIVE
I/dalvikvm(361):   | group="main" sCount=0 dsCount=0 obj=0x4051d580 self=0x29a1a8
I/dalvikvm(361):   | sysTid=370 nice=0 sched=0/0 cgrp=default handle=2728672
I/dalvikvm(361):   | schedstat=( 277421205 460097188 88 )
I/dalvikvm(361):   at android.webkit.BrowserFrame.stringByEvaluatingJavaScriptFromString(Native Method)
I/dalvikvm(361):   at android.webkit.BrowserFrame.stringByEvaluatingJavaScriptFromString(Native Method)
I/dalvikvm(361):   at android.webkit.BrowserFrame.loadUrl(BrowserFrame.java:246)
I/dalvikvm(361):   at android.webkit.WebViewCore.loadUrl(WebViewCore.java:1570)
I/dalvikvm(361):   at android.webkit.WebViewCore.access$1400(WebViewCore.java:53)
I/dalvikvm(361):   at android.webkit.WebViewCore$EventHub$1.handleMessage(WebViewCore.java:956)
I/dalvikvm(361):   at android.os.Handler.dispatchMessage(Handler.java:99)
I/dalvikvm(361):   at android.os.Looper.loop(Looper.java:123)
I/dalvikvm(361):   at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:629)
I/dalvikvm(361):   at java.lang.Thread.run(Thread.java:1019)
E/dalvikvm(361): VM aborting

I have been at it for over a day now. Any help would be most welcome:)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T01:43:28+00:00Added an answer on June 2, 2026 at 1:43 am

    Apparently, this has been a long standing bug in the 2.3.3 emulator.

    See the below link.

    http://groups.google.com/group/android-developers/browse_thread/thread/992ca132e15745ec/da8da866d107e8b3?pli=1

    Currently downloading 2.2 and 3.0 emulators.

    Thank You for all the help, and the great forum.

    I will be back with more questions!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to setup a application to load URL in Webview and then
I am new to Android and trying to setup Android Development Environment. I have
Hello StackOverflow Users, I am new to android and trying to develop a game
I'm trying to record audio this.recorder = new android.media.MediaRecorder(); this.recorder.setAudioSource(android.media.MediaRecorder.AudioSource.MIC); this.recorder.setOutputFormat(android.media.MediaRecorder.OutputFormat.DEFAULT); this.recorder.setAudioEncoder(android.media.MediaRecorder.AudioEncoder.DEFAULT); this.recorder.setOutputFile(pruebaAudioRecorder.mp4); **this.recorder.prepare();**
I'm new to Android and I think I'm trying to do something really basic:
I am new to android development and I've hit a hurdle when trying to
I'm fairly new to Android, and am trying to build a custom component in
I'm new to Android development, i'm trying to port an IOS app to Android.
I'm new in Android Programming. I'm trying to write an app that uses USB
I'm trying to share some text using an intent: Intent i = new Intent(android.content.Intent.ACTION_SEND);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.