0

How can I pass a json variable to my html page in Android, using PhoneGap?

My code:

public class Activity extends DroidGap {
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    String json = readFile();

    // I would pass json to menu.html
    super.loadUrl("file:///android_asset/www/menu.html");
}
};

Thanks a lot.

3 Answers 3

2

Maybe you can use the localStorage to pass your json.

window.localstorage.setItem("Json", json);

and when you want to get this json

string json = window.localstorage.getItem("Json");
Sign up to request clarification or add additional context in comments.

Comments

0

You should only be doing this if you are writing a Cordova (PhoneGap) plugin. If this is the case, you should be extending CordovaPlugin, not DroidGap. Then you will be able to return data to the JavaScript via a PluginResult object or the convenience method callbackContext.success(json) Have a look at the Plugin Development Guide, specifically the page on developing for Android.

Comments

0
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    super.init();

    myclass = new MyClass(this, appView);
    appView.addJavascriptInterface(this, "MyTeam");       

    super.loadUrl("file:///android_asset/www/menu.html");
}

and

 public class MyClass {

    private WebView mAppView;
    private DroidGap mGap;

    public MyClass(DroidGap gap, WebView view){


        mAppView = view;
        mGap = gap;
    }
 }

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.