Communication between an android c native application and an android application - android

I want to ask if someone know how to make communicate a native c android application and an classic java android application, the native c android application running in background.
Thanks.

First thing you need to do is download the android-ndk available here. It comes with it's own documentation which will be available here: [android-ndk path]/documentation.html, You can also find information in the android-ndk link above.
If you're anything like me you'll need as much help as you can get developing a JNI bridge. I had to find these resource myself but they were invaluable to me. See below for JNI information:
Table Of Contents
Methods (older resource)
Methods (newer resource)
Types
Reference
You can integrate your NDK/C++ code and debug it from Eclipse using Sequoyah and CDT (C/C++ Development Tooling)
More specifically to answer your question - You can use a service as a wrapper around your native code if you require the native code to run in the background. This will enable you to push information to the native code using the OS's intent mechanism in a fifo structure.

Related

Android application only in C++

Is it possible to make an Android application only in C++? I don't know Java. I've tried Visual Studio 2019 approach but I guess my computer isn't good enough for emulating Android phone.
You can write code for Android in C++, if you have the appropriate programming tools. You'll need a cross-compiler and linker for the appropriate architecture. These are readily available in Google's Native Development Kit:
https://developer.android.com/ndk/
I don't know if these tools can be used with Visual Studio -- I suspect it will be fiddly to set up.
The problem with programming in C or C++ for Android is that it's hard to integrate the application with the regular launcher and, even if you can do that, it's hard to provide a regular Android graphical user interface. Android simply does not provide a C API for the user interface.
I write/port a lot of command-line stuff for Android, so the lack of a graphical user interface doesn't bother me. However, most developers provide the user interface in Java and, if parts of the app needs to be in C or C++, it gets integrated with the app in the form of a native library.
Android Studio and similar tools know how to manage a project that has a mixture of C or C++ and Java code. Using well-established Android tools for developing complex, mixed-code apps like this is way simpler than trying to figure it all out yourself using a hodge-podge of tools from different places.

Creating android application without Android framework

In Android Stack 4th Layer is android Framework which uses JAVA,Kotlin. If I am correct than all applications are made from this framework.
Is there some other non JVM-Language based framework from which I can made Android Apps ?
I tried QT, But It also creates some java files and uses android Framework. Is it even possible to make Android app WITHOUT EVEN ANY PRESENCE OF JAVA ?
If your objective is to simply not write in a JVM language, you are welcome to use C/C++ with the NDK, using NativeActivity as your entry point.
If your objective is to avoid the framework classes entirely, you are welcome to build your own fork of Android that contains your own code as native Linux daemons, launched by init scripts or something.
If your objective is to ship an app on the Play Store or through similar channels that avoids the framework classes entirely, AFAIK there is no option for that.
You can not create an android application without using android framework. At least, for launching your application you will have to use framework functions from "android.os" package.

Is Xamarin the right choice for Android and IOS long running service

My specific task requires that I write a long running service for Android. The service should be running all the time unless the user specifically shuts it down. This I can do. However, one of my managers suggested I look into using Xamarin so we could also run this on Windows 10 and iOS. I have no experience with Xamarin or iOS so I am struggling to find any advantage to using Xamarin for this specific task, other than perhaps the code base is all in C#.
1) Does anyone have any experience with writing this type of service in Xamarin for multiple OS and if so can you offer any insight?
2) Will I have to write separate c# code for the Android, iOS and Windows implementations of the service?
3) If anyone has any compelling reasons to champion Xamarin for this task please let me know your thoughts.
Thanks
Xamarin has ported all the Android / iOS libraries to C#. Hence you can write the code in C# language but the Android Service still works in the same way.
What you will essentially do is create a PCL code (shared library) which can be used across the platforms like iOS / Android. All you business logic goes here in this library. Make sure any platform specific code is not here.
Now you will create separate projects for Android and iOS which will use the above mentioned PCL library. This is platform specific non PCL code.
For example : In Android Project, you will still use
StartService(intent) to start the service but say onHandleIntent(), you will call the PCL(shared library) code.
I would recommend to inject the dependency on PCL code as and when required.
Please Note : If the lines of code in the shared library is considerably very less as compared to platform specific code then it makes no sense to choose Xamarin over native.

How to Create a android native service and use binder to communicate with it?

My basic task is to create a native service in android and then write a simple native program to test it. lets say I want to write a simple service which return me sum of two integers. I have to use binders to talk to it from the program, I have tried to google around but I can't find a precise example. I need to know how to create a native service and find it in the program and if needed in Java also.
If you're creating a normal Android application using the NDK, you can't use Binder because it's not part of the NDK APIs.
Look in the NDK docs/STABLE-APIS.html for the full list of stable APIs, and this thread for an explicit comment by David Turner (the NDK maintainer) that Binder is not a supported API.
https://groups.google.com/forum/?fromgroups=#!topic/android-ndk/1QmVRrNckfM
Your options are:
Use some other form of IPC in native code - for example a UNIX domain socket
Do it in Java, using the normal Service and AIDL facilities of the Android SDK. If you wish to combine this with native code you may be able to call up to Java from native code using JNI.
(Not recommended) Copy the relevant libraries and headers from an Android Open-Source Project; build into your NDK project; and use the APIs. However this is not officially supported and is extremely likely to break your application in future releases because Google are under no obligation to maintain compatibility in such libraries (and frequently do not). It's also very difficult, since you need to find some way to register the service such that the client can find it.
The solution that I found is to use the Binders in native and use the
defaultServiceManager()->addService(
String16("TestService"),new CalcService());
and then use binders and use following on client side.
sp<IServiceManager> sm = defaultServiceManager();
sp<IBinder> binder = sm->getService(String16("TestService"));
I found examples here on how to do this:
https://github.com/gburca/BinderDemo/blob/master/binder.cpp
After studying and coding # Android NDK, I found The binder API is NOT available in Android NDK.
And even if you use android open source for invoking the binder api, maybe you will get permission denied because of the binder security checking.
Here if I want to add a service to System service, I need a system level user group. The detail codes you can find https://github.com/qianjigui/android_system_service_example. It contains C and Java level's client and service, but you need the system permission.

Sharing code between GAEJ and Android projects

In Eclipse:
Is it possible to Sharing code between GAEJ and Android projects? And or GAEJ and another GAEJ?
Thanks
there was a nice talk about GAE & Android integration on the last GoogleIO 2012:
Google I_O 2012 - Building Mobile App Engine Backends for Android, iOS and the Web
they show how to use same data structures for data exchange between Android and GAE.
If you asking about how to set it up in Eclipse, I use the 'linked source' option in the source tab of Java Build Path. Here's a blog post with details:
http://blog.christoffer.me/2011/01/sharing-code-between-multiple-java.html
If you are asking about whether it is practical - from the code perspective - that is trickier.
When trying to share Android code with GAE/J I discovered that I had dependencies on android packages, e.g. android.util.Base64. Sharing code means dropping stuff like this and using 3rd party libraries instead. For example, the Guava library works on GAE/J and Android:
http://code.google.com/p/guava-libraries/
Logging is another problem. My GAE/J code was writing to java.util.logging.Logger, whereas my Android code ultimately logs to 'android.util.Log.println. If you use a common library framework like log4j or just writing to System.Out I think you will lose functionality in the log viewer - ideally you would have a logging library or shim that mapped to java.util.logging.Logger or android.util.Log.println depending on the platform.

Categories

Resources