如何实现工作灯和本地人混合应用之间的互动? [英] How to achieve interaction between Native and Hybrid Applications in Worklight?

查看:124
本文介绍了如何实现工作灯和本地人混合应用之间的互动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将解释我想实现用例开始。我有两个不同的应用程序:

I will start with explaining the use case I am trying to implement. I have two different applications:


  1. 原生Android应用,以及

  2. 基于工作灯,混合应用程序

用例开始与开放原生的Andr​​oid应用程序。在一个特定的事件,我打开与某些参数的混合应用程序。

The use case starts with opening native android application. On a particular event I am opening the Hybrid application with some parameters.

在混合应用程序中,我得到了本地方面,它传递的参数,现在我想用这些数据在应用程序(的JavaScript,HTML)的网页视图。我怎样才能做到这一点?

In the Hybrid application, I am getting the passed parameters in the native side it, and now I want to use that data in the webview of the application (JavaScript, HTML). How can I achieve that?

例如:结果
我开了第一家Android应用程序。其中有一个文本框和一个按钮。我输入我的手机号码的文本框,并按下按钮。点击按钮我有code这将启动其他混合应用程序,并把它传递的手机号码。

For example:
I opened the first android application. Which have one text box and a button. I entered my mobile number in text box and hit the button. On the button click I have code which starts the other hybrid application and passes the mobile number with it.

我能够提取的code的机端的手机号码参数。如何传递到它的网站(JavaScript)的一部分吗?

I am able to extract that mobile number parameter on native side of code. How to pass that to the Web (JavaScript) part of it?

任何帮助将AP preciated。

Any help will be appreciated.

推荐答案

我将使用code片段描述了解决方案。

I will describe the solution using code snippets.

首次公开从本机应用程序的混合应用程序。

First Open the hybrid application from a native application.

Intent intent = getPackageManager().getLaunchIntentForPackage("URI Of Target Application");
intent.putExtra("someData", someData);
startActivity(intent);

现在工作灯基于混合应用程序将启动,并从本地部分,我们将提取传递的数据并将其存储在共享preferences:

Now Worklight based hybrid application will start and from native part we will extract that passed data and store it in shared preferences:

Bundle dataBundle = getIntent().getExtras();
String someData = dataBundle.getString("someData");
sharedpreferences = getSharedPreferences(MyPREFERENCES, MODE_PRIVATE);
sharedpreferences.edit().putString("someData", someData);
sharedpreferences.commit();

现在让你可以在Web部件之后调用一个插件就可以使用了。

Now make a plugin which you can call after the web part is ready for use.

SharedPreferences sharedpreferences = cordova.getActivity().getSharedPreferences(MyPREFERENCES,cordova.getActivity().MODE_PRIVATE);
if(sharedpreferences!=null) {
     String param = sharedpreferences.getString("someData", "-1");
     sharedpreferences.edit().remove("someData").commit();
     callbackContext.success(param); 
}

呼叫基于工作灯混合应用程序的Web端的插件。

Call that plugin on web side of Worklight based hybrid application.

function onSuccessSharedData (param) {
     Param is the passed parameter
} 
Cordova.exec(onSuccessSharedData, onFailure, "pluginName", "action", []);

这篇关于如何实现工作灯和本地人混合应用之间的互动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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