42

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.

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.

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.

Works On Mine
  • 1,111
  • 1
  • 8
  • 20
  • Microsoft Project Ace http://microsoft.github.io/ace/docs/native-ui/#four claims to be able to update a widget from a cordova app. I have only been partially successful in getting this to work. – nwaltham Nov 08 '16 at 05:00
  • @nwaltham any success in using Ace to get the widget working? – Ari Dec 05 '17 at 06:28

2 Answers2

32

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.

Documentation:

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

Slava Shengur
  • 421
  • 5
  • 6
21

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

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.

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".

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?"

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

andmar8
  • 331
  • 3
  • 14
  • 24
    ***"If it's the former, then just write a native app"*** - I don't necessarily agree. Writing UI in HTML/JS may be way simpler than Android native code, so if an Android app contains 70% non-widget UI and 30% widget UI, I would still consider doing the non-widget part in HTML/JS/CSS. – Ilya Kogan Apr 24 '15 at 11:24
  • That is true, however I think the thrust of the question asked was more "I'm just starting out and making a small app"; in principle I agree, if you know what you are doing and are making an app of a reasonable size, a mix and match approach would be sensible. – andmar8 Jun 10 '15 at 12:08