Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript app in Android

I am new to Android programming, and looking for some general knowledge. I am considering writing logic of my application in javascript so that the same code could be executed in a webapp and in a desktop application. Would it be possible to also have it working on Android? I know that:

  • SL4A is marked as alpha-quality, and user would need to install it to make such an app work. Still it provides access to Android API. SL4A scripts also cannot go to Android Market, as far as I know.
  • A simple webapp doesn't have access to most Android API.

Would it be possible to write a simple Java app that would embed an HTML widget with javascript code and provide some wrapper to access necessary API?

I am not looking for a fully portable thing--I intend to adapt UI to each environment manually. I just would like to have the internal logic common to all ports.

like image 821
liori Avatar asked Dec 09 '10 19:12

liori


People also ask

Can you use JavaScript in an Android app?

Can we use JavaScript for Android? Yes, of course! The Android ecosystem supports the concept of hybrid apps, which is a wrapper over the native platform. It mimics the UI, UX, and all kinds of hardware and network interactions, just like how you would use a native Android app.

Can I use JavaScript for mobile apps?

Mobile Apps: For developers, though, there's a hitch: mobile apps for Android and Apple are entirely different. That's where JavaScript, specifically React Native, comes in. This JS-based tool lets developers build cross-platform mobile apps, instead of needing to code two completely separate apps.

What is JavaScript in mobile apps?

JavaScript frameworks allow the development of native mobile apps. You can build Android, iOS, and even cross-platform apps on the JavaScript app frameworks. Developers can write reusable codes with JavaScript frameworks. It becomes easy to share knowledge and use the code for future projects to save costs and effort.


3 Answers

PhoneGap allows you to write an HTML-based app that not only works with Android, but also iPhone, Windows Phone 7, WebOS and more. The API is standardized, so you can use the same page on all the platforms.

There's support for the most common native features on most platforms. (Here's a chart of the features supported on each platform) In addition, if you find that there's a feature you cannot replicate using only their API, you can write a plugin in the native platform language (so, for Android that'd be Java), and then call that plugin from your HTML/Javascript-page.

like image 170
Sebastian Paaske Tørholm Avatar answered Sep 30 '22 16:09

Sebastian Paaske Tørholm


If you want to use javascript and access the native api then you should try Appcelerator.com. Those people are providing this.

like image 29
Tarik Avatar answered Sep 30 '22 16:09

Tarik


There is Rhino, which is a Javascript engine written in Java. It works in Android, and it is used by Appcelerator's Titanium mentioned in another answer here.

User interface and Android-specific API can then be written and wrapped in Java, then called by the logic code written in Javascript and run by Rhino.

like image 40
liori Avatar answered Sep 30 '22 14:09

liori