使用 Cordova 的 Android 小部件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25938933/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 09:51:45  来源:igfitidea点击:

Android Widget using Cordova

androidcordovawidget

提问by Works On Mine

I am planning to bundle together some minimal functionality into an app or a widget for android devices. However on second thought I realized that I have never heard/read someone building a widget with Cordova/Phonegap before. I googled a bit and the answers seem to be suggesting a 'no'. I read the description on the home page for Phonegap and it says that it allows users to build apps basically.

我计划将一些最小的功能捆绑到一个应用程序或一个用于 android 设备的小部件中。然而,转念一想,我意识到我以前从未听说过/读过有人用 Cordova/Phonegap 构建小部件。我用谷歌搜索了一下,答案似乎在暗示“不”。我阅读了 Phonegap 主页上的描述,它说它基本上允许用户构建应用程序。

So, could someone please point me in the right direction as to wether its possible to create an android widget in Cordova. And if no, how is an widget conceptually/practically different from an app.

所以,有人可以指出我是否有可能在 Cordova 中创建一个 android 小部件的正确方向。如果不是,小部件在概念上/实际上与应用程序有何不同。

PS: just maybe i am using some incorrect terminology here. What I mean by a widget is this. Its something that sticks on the home screen mostly in a translucent bar.

PS:也许我在这里使用了一些不正确的术语。我所说的小部件的意思是this。它主要是在主屏幕上的一个半透明栏中。

采纳答案by andmar8

Widgets are android native constructs that extend a view on the application screen.

小部件是 android 原生结构,可扩展应用程序屏幕上的视图。

http://developer.android.com/reference/android/widget/package-summary.html

http://developer.android.com/reference/android/widget/package-summary.html

A cordova/phonegap app is an app with a webview backing. Note: webview not android native view.

cordova/phonegap 应用程序是一个带有 webview 支持的应用程序。注意:webview 不是 android 原生视图。

Until someone finds a way to construct a native widget that embeds a webview, then what you have been told so far is correct... i.e. "no".

直到有人找到一种方法来构建一个嵌入 webview 的本机小部件,那么到目前为止你被告知的是正确的......即“不”。

http://cordova.apache.org/docs/en/4.0.0/guide_overview_index.md.html#Overviewhttp://cordova.apache.org/docs/en/4.0.0/guide_hybrid_webviews_index.md.html#Embedding%20WebViewshttp://cordova.apache.org/docs/en/4.0.0/guide_platforms_android_webview.md.html#Android%20WebViews

http://cordova.apache.org/docs/en/4.0.0/guide_overview_index.md.html#Overview http://cordova.apache.org/docs/en/4.0.0/guide_hybrid_webviews_index.md.html#Embedding %20WebViews http://cordova.apache.org/docs/en/4.0.0/guide_platforms_android_webview.md.html#Android%20WebViews

Edit: It "is" conceivable you could have a widget associated with your cordova project, but then you would be writing android native code alongside cordova.... most people would see this as defeating the point of using cordova, unless you are ONLY targeting android. In which case I have to ask the question:

编辑:“是”可以想象你可以有一个与你的科尔多瓦项目相关联的小部件,但是你会在科尔多瓦旁边编写安卓本机代码......大多数人会认为这违背了使用科尔多瓦的意义,除非你只是针对安卓。在这种情况下,我不得不问这个问题:

"Are you using cordova as an easier way to start app coding on android or are you trying to leverage the convenience of cordova to share a code base across multiple platforms?"

“您是将cordova 用作在android 上开始应用程序编码的更简单方法,还是试图利用cordova 的便利性跨多个平台共享代码库?”

If it's the former, then just write a native app. If it's the latter, then cordova isn't going to (easily) give you widgets, nor cross platform widgets

如果是前者,那么只需编写本机应用程序即可。如果是后者,那么cordova 不会(轻松)为您提供小部件,也不会提供跨平台小部件

回答by Slava Shengur

Yes, widgets are native Android constructions. But you CAN create your widget for your app with the help of cordova plugin called "cordova-plugin-ace". Made by Microsoft and opened to everyone.

是的,小部件是原生 Android 结构。但是您可以借助名为“cordova-plugin-ace”的cordova插件为您的应用程序创建小部件。由微软制造并向所有人开放。

Documentation:

文档:

I hope it'll be helpfully for you, me and others cordova devs.

我希望它对你、我和其他科尔多瓦开发者有所帮助。