简体   繁体   English

在Android中使用Cordova插件

[英]Using Cordova Plugin in Android

I'm using Cordova for create an App in Android and iOS, in iOS I did not have any problem, and the app is now in the App Store. 我正在使用Cordova在Android和iOS中创建应用程序,在iOS中我没有任何问题,该应用程序现在已在App Store中。

I have some questions for Android, because I am desperate... 我对Android有一些疑问,因为我很拼命...

I created the Project using cordova platform add android , and the project created fine. 我使用cordova platform add android创建了Project,并且项目创建良好。 I can load and compile, and all works fine, except the plugins... I have added the plugins correctly and works fine in iOS using the command cordova plugins add org.cordova... 我可以加载和编译,并且除插件外,其他一切工作正常。我已正确添加了插件,并使用命令cordova plugins add org.cordova...在iOS中正常工作了cordova plugins add org.cordova...

Can someone tell me how I need to use the plugins in Android? 有人可以告诉我如何在Android中使用插件吗? Do I need include any .js (of course Cordova.js is include, but I don't know how exactly is my project using it, like a charm...). 我是否需要包含任何.js(当然,包含Cordova.js,但我不知道我的项目使用它的精确程度如何,例如超级按钮……)。

I just can see an error in LogCat that say: 我只是可以在LogCat中看到一条错误消息:

error adding plugin org.apache.cordova.inappbrowse

The app works, but the alerts is showing the typical alert of a browser and the links is open inside my App, I use it with this code: 该应用程序正常运行,但是警报显示的是浏览器的典型警报,并且链接在我的应用程序内部打开,我将其与以下代码结合使用:

$('a[target=_blank]').on('click', function(e) {
                             e.preventDefault();
                             window.open($(this).attr('href'), '_system');
                             return false;
                         });

And for the notifications: 对于通知:

navigator.notification.alert("Hello!", null, "Title", "Close");

Can someone show me a way to solve the problem? 有人可以告诉我解决问题的方法吗? An example? 一个例子?

Just for information... I have tried this very simple example ( Link ) in a new separate project and App and I have the some error... Maybe the error is in the Config.xml? 仅供参考...我已经在一个新的单独项目和App中尝试了这个非常简单的示例( Link ),并且出现了一些错误...也许该错误在Config.xml中? How I need to use it for Android? 我需要如何在Android上使用它?

Thank you so much!! 非常感谢!!

Run it and watch console. 运行它并观察控制台。 If you get a "Refused to execute inline event handler" type message then add 'unsafe-inline' to your default source in the content security policy of your config.xml file. 如果收到“拒绝执行内联事件处理程序”类型的消息,则在config.xml文件的内容安全策略中将'unsafe-inline'添加到默认源中。

<meta http-equiv="Content-Security-Policy" content="default-src 'self'   
data: gap: https://ssl.gstatic.com 'unsafe-inline' 
'unsafe-eval'; style-src 'self'; media-src *;">

Details on the policies are available at https://developer.chrome.com/extensions/contentSecurityPolicy . 有关政策的详细信息,请访问https://developer.chrome.com/extensions/contentSecurityPolicy

Hope this helps. 希望这可以帮助。 Healy in Tampa. Healy在坦帕。

卸载所有插件,然后再次重新安装可以解决我的问题。

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

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