2
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    web = (WebView) findViewById(R.id.webview1);



    web.setWebChromeClient(new MyWebChromeClient());

    web.addJavascriptInterface(new DemoJavaScriptInterface(), "temp_1");

    web.loadUrl("file:///android_asset/temp_1.html");

  }   
}

final class DemoJavaScriptInterface {

    private Handler mHandler = new Handler();
    WebView web;
    DemoJavaScriptInterface() {
}

public void clickOnAndroid() {
    mHandler.post(new Runnable() {
        public void run() {
            web.loadUrl("javascript:init();");
        }
    });

   }
}

final class MyWebChromeClient extends WebChromeClient {

    private static final String LOG_TAG = "WebViewDemo";
    @Override

    public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
        Log.e(LOG_TAG, message);
        result.confirm();
        return true;
    }
}

2 Answers 2

1

Try to write this line

web = (WebView) findViewById(R.id.webview1);
web.setWebChromeClient(new MyWebChromeClient());

web.getSettings().setJavaScriptEnabled(true);

web.addJavascriptInterface(new DemoJavaScriptInterface(), "temp_1");
web.loadUrl("file:///android_asset/temp_1.html");
Sign up to request clarification or add additional context in comments.

Comments

0

[2]: Both Elements are coming from html file ,when going to click on "Click It" nothing happens instead of displaying xml data that i want

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.