2

I believe that there is a way to pass the json objects from JS to java using phonegap plugin. If anybody knows please help me on this. Thanks in advance buddies

1 Answer 1

1

Create a java class like this

public class MyJavaScriptInterface 
{

    Activity parentActivity;
    MyJavaScriptInterface(Activity activity){
             parentActivity = activity;
    }

    public void processData(String jsonString){
        /* your processing logic */

    }

in your activity

MyWebView.addJavascriptInterface(new MyJavaScriptInterface(this), "MyHandler");

in your html page 



<a href="#" data-transition="slide" onClick="window.MyHandler.processData("+jsonString+")">

Change this with your page code (html Page)
Sign up to request clarification or add additional context in comments.

1 Comment

by sending JSON data like this I'm getting this error Uncaught SyntaxError: missing ) after argument list", source: file:///android_asset/' my code formatted like this with including JSON data <img src="http://45.55.46.149/wp-content/uploads/2017/12/android-smart-text-selection-350x175.jpg" onClick='window.JavaScriptInterface.showImages("[{"name":"John","age":30,"city":"New York"}]");' />

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.