如何从JS JSON对象传递给Java的android系统中的PhoneGap? [英] How to pass Json objects from js to java in android phonegap?

查看:144
本文介绍了如何从JS JSON对象传递给Java的android系统中的PhoneGap?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为,是通过从JS到Java中使用PhoneGap的插件JSON对象的方法。如果有人知道,请帮助我在此。在此先感谢哥们

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

推荐答案

创建一个Java类像这样

Create a java class like this

public class MyJavaScriptInterface 
{

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

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

    }

在您的活动

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)

这篇关于如何从JS JSON对象传递给Java的android系统中的PhoneGap?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆