Running JavaScript methods from Java in Android - android

I am writing application using PhoneGap on Android. I need to call some PhoneGap methods from native Java code. Anyone knows how to do that??

If you write your native code as an Android plugin (see an example here: https://github.com/phonegap/phonegap-plugins/tree/master/Android/BarcodeScanner) then you have access to all of the PhoneGap Java classes and can call them as you like.

Related

Is it possible to expose C API in SO library to access Android JAVA methods?

I'm new to JAVA/Android development.
I'd like to abstract Android JAVA BLE interface and deliver higher level API in C/C++ to different team that code in javascript and is capable to call C/C++ library methods. They are working on Firefox build for different platforms and Android is the one we are working on now.
Is it possible to expose a C/C++ interface in native code (*.so library) which they can use to access JAVA methods?
I've got familiar with native code concept and it is more to be called from JAVA. It is also possible to call JAVA code from C/C++ by finding a class and a method ID but I can't understand if those C/C++ functions could be called from the external code loading the *.so library?
Is java code also required to be delivered with *.so library so it can actually call JAVA methods or is JAVA code also built into *.so file?
I think it is possible in principle, but it would be something like this:
Android app has JavaScript engine that run JavaScript code, JavaScript code calls "native" method, engine calls C code (or it can be event worse and call Java code, which in turn call C code), C code calls Java code.
I don't see why you need extra steps here when you can have direct: JavaScript engine calls Java code.

How to call a C function from a react-native code?

I have developed a small android application using react-native. For what it was developed, it works fine. Now to accommodate a small requirement, we need to call a library written in C. I am not sure if there will be a way to call the C code from JavaScript! But I still wanted to ask you all.
Is there a way to do this from react-native? Like I want to call some functions in the C library. If this possible, could you please suggest how? How could I start to test a very basic setup?
You are going to have to write some native code, search for how to call a C lib on Android, then look for react native way to link a native code with a js call.
Native Module link https://facebook.github.io/react-native/docs/native-modules-android.html
StackOverflow question on how to run c/cpp code on android how to use c/cpp library/functions in android
Basically it includes 3 parts.
JavaScript to Java or Kotlin
check out React Native's guide to Android Native Module.
Java or Kotlin to C
Calling C functions from Java is enabled with a mechanism called Java Native Interface (JNI) . check out how to add C and C++ code here.
see more here https://thebhwgroup.com/blog/react-native-jni

Calling an activity from jquery in cordova

I am new to cordova so wanted to know if it is possible or not.
I have a functionality to implement, which I think I will be more comfortable in android native activity.
So can I call the native android from an html page or through jquery and the vice versa.
You need binding JavaScript code to Android code (bridge)
See official documentation
here is a good tutorial
http://itsmycodeshare.blogspot.in/2016/01/create-custom-cordova-plugins-using.html
and this is basic plugin example which interacts with js from Android java
https://github.com/don/cordova-plugin-hello
add your further activity and other code in <plugin_name>.java in src folder.

Can we use native code as plugin in Rhomobile?

I need to run a java code for Android inside Rhomobile app. Is there any way i can call the java code. I have seen some of the plugins to interact with native codes for Android.
I tried searching and i did get to this url http://docs.rhomobile.com/rhoconnect/plugin-intro.
But i guess this is not for Rhomobile if i'm not wrong.
I have a library file for my requirement. Is there any way i can use it ?
Yes you can. Have a look at this http://docs.rhomobile.com/rhodes/extensions#native-extensions
The link you get is for RhoConnect ( basically meant for sync operation). You need to look into the native extension for Android : Rewriting the Generated Native Extension Source Code for Android
If you need some more help and support, you can go over
https://developer.motorolasolutions.com/‎
https://groups.google.com/forum/#!forum/rhomobile
You can also simply post you query here and tag Rhomobile & Rhodes.
Hope this might help you.

How to connect html to native using phonegap in android

i started working on android using phonegap. In iphone we use phoneGap.exec(classname.methodname, arguments) to connect to the native application from html. But how can you do it in Android? Can anyone help me in this please?
Thanks in advance,
Bharath gangupalli
Sounds like you're trying to connect to a native plugin. The technique is generally the same on Android, include the native code and then call out using the Phonegap.Exec() wrapper. If you're looking for a sample to start from try out the BarcodeScanner plugin, which includes native code and the JS wrapper to call out to it:
https://github.com/purplecabbage/phonegap-plugins/tree/master/Android/BarcodeScanner

Categories

Resources