简体   繁体   English

Cordova插件可将数据从本地android活动发送到javascript代码

[英]Cordova plugin to send data to javascript code from native android activity

I am doing a Hybrid Android app. 我正在做一个Hybrid Android应用。 My landing page will be a custom android activity which will have login and signup buttons. 我的登录页面将是一个自定义android活动,其中将包含登录和注册按钮。 Once I click any of these buttons, another activity which is a subclass of CordovaActivity should be launched and load the corresponding html view in CordovaWebView of the activity. 单击这些按钮中的任何一个后,应启动另一个作为CordovaActivity子类的活动,并在该活动的CordovaWebView中加载相应的html视图。 However I am facing issues in sending which html view (login/signup) should be loaded in the CordovaWebView upon the button click. 但是,在单击按钮后,应该在CordovaWebView中发送哪个html视图(登录/注册)时遇到问题。 That is how should i send some parameters from native android activity to javascript to identify login/signup ? 那就是我应该如何从本地android活动向javascript发送一些参数以标识登录/注册?

I know this question is a bit old. 我知道这个问题有点老了。 But why not perform the condition check in your native activity, and save the required condition in your SQLite DB. 但是,为什么不在您的本机活动中执行条件检查,然后将所需条件保存在SQLite DB中。 As in : 如:

if (buttonAIsClicked) {
    saveConditionsForButtonA();
} else if (buttonBIsClicked) {
    saveConditionsForButtonB();
}

Then upon load of your CordovaActivity, (JavaScript Code = ng-controller) check your DB for the value of the clicked button based on the saved value 然后,在加载CordovaActivity时(JavaScript Code = ng-controller)根据保存的值检查数据库中被单击按钮的值

var buttonClicked = getWhichButtonWasClicked(); //from DB 

and act accordingly. 并据此采取行动。

if (buttonClicked == buttonA) {
    $state.go(paramNameA);
} else if (buttonClicked == buttonB) {
    $state.go(paramNameB);
}

I know this is a hack. 我知道这是黑客。 But that is how I did it, and it worked. 但这就是我做到的方式,并且它起作用了。

I hope this will be of help. 我希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM