Run native code in Phonegap (Java Android) - java

I need to generate pulses to create a frequency from my android device (to communicate to arduino via the audio jack, but this is not important). Natively, java allows us to do that as explained here.
Unfortunately this is impossible to do via javascript, so I need to run this native code in my app through Javascript.
I'm a complete ignorant about "running Java from JS", so, can you suggest me a tutorial where to learn from, or help me somehow?

You need to write an Android plugin for this, Phonegap Android Plugin is the phonegap API documentation for writing a plugin. You need to call your Android Plugin through JavaScript.
Here is a Sample PhoneGap plugin for Android

Related

Porting an SDL 2.0 game to Android

I have a game written in C/C++ with SDL 2.0, I would like to port it to mobile platforms (specifically Android and maybe other platforms too). I read SDL has a native support for Android but the game itself is written for Windows at first, although no Windows-dependent libraries/code were used. As for Android, I only used the Java based SDK before and never integrated it with native code. Which changes (if any) do I have to make to the C/C++ so I could use it on Android platform? How exactly do I acually compile the whole thing to an APK? Is it possible to use Java and C/C++ for the application, I mean, the game's activity will be the native one but the other activities (menus, settings, etc) can be written with the regular Android Java SDK?
The Android README file in the SDL source release outlines most of what you need to know with regards to porting your SDL App to Android. There's also an example project for Eclipse that demonstrates you can modify to suit your needs.
https://hg.libsdl.org/SDL/file/d6a8fa507a45/README-android.txt
The iOS README file is also useful, namely for the sections on events and input, as much of it carries over to the Android port.
https://hg.libsdl.org/SDL/file/d6a8fa507a45/README-ios.txt
If you need help setting up the build environment, check out this (brief) tutorial which covers installing the ADK and NDK, SDL source, building a project, programming for Android and interfacing with Java.
http://www.dinomage.com/2013/01/howto-sdl-on-android/
http://www.dinomage.com/2013/05/howto-sdl-on-android-part-2-platform-details/
(1)
I dont know anything about SDL but as long as you only make calls suported by the android NDK and what ever android supported library it should be ok. I guess you would have to set up your tool chain such that it links with SDL for android?
(2)
Yes it is possible to call c++ (ndk) from the android sdk and vice versa (see 3)
(3+ rest)
See
https://developer.android.com/tools/sdk/ndk/index.html
If you download the NDK you can also see examples of how to compile with NDK to APK

Pass java variables from Android activity to javascript in phonegap application

I am developing cross platform applications that target Android, iOS, Blackberry and Windows Phone Platforms. I am using Jquery Mobile 1.3.1, jquery 1.9.1 and Phonegap 2.8.0.
I want to be able to pass variables from an Android activity to javascript.
How can I call a javascript function from an activity and also call a method in java from javascript.
I browsed for a solution, but, could not understand the usage of sendJavascript() and loadUrl().
Could someone please help me Understand this. I am new to Android and cannot understand how to get this done.
Thanks in advance.
Solution is: Phonegap plugin.
A Phonegap plugin bridges a bit of functionality between the WebView
powering a Cordova application and the native platform the Cordova
application is running on.
It is well explained with each platform in official phonegap doc.Here you can read more about Android plugin of phonegap.
And here a very nice tutorial on how to Write a PhoneGap 3.0 Plugin for Android .

how to embed a c library in android

I have an iphone app. I made my source code as boost library. Is there any possibility to embed my library to my android app? I am using eclipse. Can any one send any link about this.
At least a simple C or C++ library embedding to android and using those functions in my android app?
You need to use Android NDK tool chain for cross compiling the library. This link shows how to use it -
"http://www.cmumobileapps.com/2011/08/31/compiling-open-source-libraries-with-android-ndk-part-1/"
If you need support of STL, RTTI, C++ exception, then there's a patched up NDK available at http://www.crystax.net/android/ndk-r4.php

Run a native app with a web app on PhoneGap

my question is: Is posible to run a native app using a web app developed on phonegap?, I need to make that, I was reading about is necessary create a plugin to connect with other native app, but I'm starting to programming over phonegap I still don't understand much, and need to create that. But I need some very explicit.
Thanks.
Yes, you can create a PhoneGap native plugin that will enable you to create custom functionality in native code, and expose that to your PhoneGap applications via PhoneGap's native-to-JavaScript bridge. For more information about plugins and example of how to implement them check this tutorial:
http://www.adobe.com/devnet/html5/articles/extending-phonegap-with-native-plugins-for-android.html

using jquery mobile with java, is it possible?

I need to know how to use the jquery mobile with java coding in the same application, so I can merge some features not available in the jquery platform to make some advanced android application.
appreciate your responses.
First don't listen personne3000, apparently he never touched Phonegap.
It can be done with jQuery Mobile if you use it with Phonegap. Phonegap, while working as a wrapper for HTML5/JS/CSS will give you access to native JAVA code (Android only of course). Phonegap will give you access to the wide range of mobile phone compatibilities ranging from camera, sound record up to creating native tab bar for your app.
Here you will find a "iOS Getting started" tutorial for Phonegap/Cordova and here's an Android tutorial.
Here you can find basic Phonegap/Cordova API reference and this is just a basic list, much more can be found in 3rd party plugin list here.
In case you can't find functionality you need you can create your own plugin and here you will find a Phonegap plugin tutorial for Android platform. In case you are going to use an older version of Phonegap (pre Cordova) here's an older plugin creation tutorial.
I don't think you can directly use jQuery mobile to develop your app. However, you can :
Develop an Android application using Phonegap or Cordova in HTML5/Javascript, and use jQuery mobile, but you won't have access to Java
Use WebViews to display webpages with Javascript included. You might want to look at the addJavascriptInterface method.
Javascript and Java can't be mixed just like that in an application : they work very differently.

Categories

Resources