简体   繁体   English

是否可以将 Cordova exec 命令从外部网络发送到 cordova 应用程序?

[英]Is it possible to send Cordova exec command from external web to cordova app?

My question is that is it possible to send cordova.exec() from external web to cordova app ?我的问题是是否可以将 cordova.exec() 从外部网络发送到 cordova 应用程序?

Below is the detail scenario of my requirement...以下是我的要求的详细场景...

I built an Android app with cordova cle, ( CordovaActivity )我用cordova cle构建了一个Android应用程序,( CordovaActivity )

and implement pluginA,并实现pluginA,

I'm sure this plugin can successful run when I use cordova.exec inside the app.当我在应用程序中使用 cordova.exec 时,我确信这个插件可以成功运行。

In the other side, I use webView to load external page,另一方面,我使用 webView 加载外部页面,

like this loadURL("some webpage I'd wrote.").就像这个 loadURL("我写的一些网页。")。

In that webpage, I include cordova.js and send cordova.exec( pluginA );在那个网页中,我包含了 cordova.js 并发送了 cordova.exec(pluginA); , ,

but nothing happened instead of getting alert dialog.但没有发生任何事情,而不是得到警报对话框。

( gap_init:2 ) ( gap:[null,"CoreAndroid","messageChannel","CoreAndroid555630745"] ) ( gap:[null,"CoreAndroid","show","CoreAndroid555630746"] ) ( gap_init:2 ) ( gap:[null,"CoreAndroid","messageChannel","CoreAndroid555630745"] ) ( gap:[null,"CoreAndroid","show","CoreAndroid555630746"] )

In short: Can we use cordova.exec() to invoke native plugin from an external web page?简而言之:我们可以使用 cordova.exec() 从外部网页调用本机插件吗?

Thanks All.谢谢大家。

From what I had read, your issue seemed to be you want to load an external web url directly inside a Cordova app.从我读过的内容来看,您的问题似乎是您想直接在 Cordova 应用程序中加载外部 Web url。 From your external web source codes, you want to be able to perform native calls through cordova.从您的外部 Web 源代码中,您希望能够通过 cordova 执行本机调用。

If that is what you want, you can use the cordova-plugin-remote-injection .如果这是您想要的,您可以使用cordova-plugin-remote-injection

What it does is when you load an external url, it automatically injects the plugins you had installed within your Cordova application.它的作用是当您加载外部 url 时,它会自动注入您在 Cordova 应用程序中安装的插件。 Afterwards, you can use the variable cordova in your external source code.之后,您可以在外部源代码中使用变量cordova

The whole process is really simple, just install the plugin and the rest is automatically done for you.整个过程非常简单,只需安装插件,其余的会自动为您完成。

Just remember to update your index.html file within your Cordova application.请记住在您的Cordova应用程序中更新您的index.html文件。 and set the meta to something like this allow the injection to take place.并将meta设置为这样的东西允许注入发生。

<meta http-equiv="Content-Security-Policy" content="gap://ready file:;script-src 'self' data:;">

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

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