I'm newbie to Android development, but I am linux c/c++ background guy.
Now, I have linux c++ network proxy program, which is TCP Server and Client written in boost library. The function of this proxy program is
TCP server will receive Android app's request, and translate that
request to some specific format
then behave as client to send out translated thing to correct remote computer (like router)
My task is to porting this program on Android system. And hope the Android native application communicates with this proxy program through socket like in Linux.
I search the web, try to find the proper way to do this. But, it seems that most of existing things I found are java JNI library based solution.
I wonder if this could be done in daemon or service process way. The proxy program is a bit large, so, re-write is a real pain for me.
Any suggestion or solution would be highly appreciated. Thanks advance!
Jeff
Unless we are talking about rooted devices, there is no way around on having to deal with Java on Android, at some level in the stack.
You can wrap your code in a Native Activity, which basically means an existing Android Java class that knows how to load a set of predefined public symbols from an .so file.
https://developer.android.com/reference/android/app/NativeActivity
https://developer.android.com/ndk/guides/stable_apis#native-application-apis
The problem here would be when to launch the said activity, as there is no guarantee to keep it running.
Android doesn't have daemons on the UNIX sense, only services.
So as alternative you could create an Android service class, however starting with version 8, there are execution restrictions. Meaning you cannot have it run forever on the background.
https://developer.android.com/guide/components/services
Possibly by using a bound service, which the applications would need to connect to before talking via sockets might do what you need.
https://developer.android.com/guide/components/bound-services
Related
I have an Android app that serves as a GUI to a little daemon (written in C++) that needs to run on an variety of mobile/embedded linux devices. The daemon needs to collect GPS data and pass it to several clients (android phones, each with a GUI). The daemon needs to be capable of running on one of the same Android devices that is being used as the GUI, but I'm having a lot of trouble accessing GPS data from the C++ daemon.
I've looked into two options so far:
1) The "stay native" method: I've heard that gpsd exists for Android (such as here http://esr.ibiblio.org/?p=4886), but it seems elusive and/or not existent on my Samsung Galaxy SII, running Cyanogenmod 10.1.3-i9100 (Android 4.2.2). My standalone toolchain built from the NDK doesn't seem to have anything gps-related at all, even though sites like this one (http://www.jayway.com/2010/01/25/boosting-android-performance-using-jni/) indicate that java uses JNI wrappers to use C code to talk to the GPS anyway.
2) The jni method: GPS seems really easy in Android Java applications, so I started looking into the JNI (I'm pretty new to Android and Java, by the way). It is supposed to proved a way for C code and Java code to interact, right? I read up on it at this site (http://journals.ecs.soton.ac.uk/java/tutorial/native1.1/implementing/index.html) and this site (http://journals.ecs.soton.ac.uk/java/tutorial/native1.1/implementing/index.html) and a bunch of others. But it occurs to me I haven't seen any C code using the JNI that has a main() function in it. Also, the JNI_CreateJavaVM() function is commented out in the jni.h header file of my NDK toolchain. In fact, I can't figure out how to have a valid JNIEnv* in the first place. The conclusion I've come to is that JNI code is meant to be used by Java applications that need C support, not C applications that need Java support. Is that correct?
And then I have a third thought, which I don't like very much:
3) the "backup" method: In the instances where the C++ daemon is running on an Android phone, perhaps it could ask the android GUI for GPS data, then broadcast that to the other clients? I'm thinking they might communicate through a socket or something simple. This seems like a really ugly solution though, because on top of seeming inefficient, the daemon should be able to run independent of any GUI, but now it would depend on the GUI for GPS data.
So my real question is, has anybody else ran into this problem and found a suitable answer? Or perhaps there is something I am not understanding something aobut gpsd in Android, or about JNI in Android?
Thanks for reading.
I would recommend you to try to use this code: Android GPS using libhardware.
This small project use libhardware library from AOSP. See gps.h for more information about how to use GPS abstraction interface. Also worth a look GpsLocationProvider.java and com_android_server_location_GpsLocationProvider.cpp.
I am developing an Android application, in which I want to make a calls using internet using SIP in android. So I need to maintain my own SIP sever for my app users, how can I create my own SIP server?
I would not advise creating your our sip server as it would take a large number of man years of development and there are a lot of pitfalls.
There are some open source implementations that you could install and setup yourself. Like FreeSwitch or Asterisk. Both are large and complete to setup as there is a lot of domain knowledge required to understand how to set them up correctly.
There are also free server that you could try out as well like Sip2Sip.
Then there is the job of creating a sip client on Android. Again it's not that simple either. I would look at using a open source library here as well, like pjsip. This gives you the advantage of being able to look at examples of full sip clients already developed for Android like csipsimple. pjsip also has the advantage of being cross-platform, so you could reuse it in IOS for example.
Good luck.
The Server
As a communication server, choose for example sip:providerCE v2.6. The easiest way to get started with it is to download the VMware or Virtualbox image and fire it up on a suitable machine. If you get more serious, you want to install the system from scratch on a dedicated server with a public static IP. If you’re new to VoIP and SIP, do NOT try to install it on an Amazon EC2 instance, as they’re using destination NAT, which is a big pain for SIP and needs some experience with the SPCE to tweak it properly for that scenario.
Note that the SPCE is a 64bit system, so in order to run the VM images, you need to turn on 64bit CPU virtualization in your BIOS if VMware or Virtualbox warns you about it.
...There is very good tutorial HERE! on how to set things up.
...Don't forget there is a technical advise concerning SIP check the accepted ANS!
...Least but not last check THIS! VOIP Wiki, It covers everything related to VOIP.
SIP RFC is very easy protocol to implement. Just create a socket listener and implement RFC-3261. Start with with a basic codec GSM, then move up to A-LAW (G.711), as needed.
The tricky parts with SIP are (A) ensuring your call flows are correct (RFC-3665) and (B) media encoding/compresion. Use Asterisk (FreeSwitch) and WireShark to test your call flow. If you need DTMF support you'll need RFC-2833. If you need advanced codecs, consider using open-source library like FFMPEG.
I used uSIPserver on android. It works well and support video call. If you use client app which supports video then you can video call eachother on wifi.
It is so simple to use.
Good luck :-)
I have an Android device that I'm using to monitor a couple of sensors with an app that I created. What useful ways are there to update the settings in my app (while it's running at a remote location) from my computer? I'm interested in sending a message to my app to tell it to email a screenshot, change sample rate, etc. Creative workarounds are encouraged.
I've already looked into C2DM and unfortunately have no experience with setting up the required third-party application server.
[EDIT] It just occurred to me that I may have grossly over simplified what you were trying to do. If this is the case my answer probably wont be of much if any help to you. The original answer follows though.
You could use TCP sockets to set up a client/server interface between your app and a command program on your computer. Then just send a set of predefined messages/commands. Two tutorials I used for learning this are Here and Here. This wont help with the computer side of the sockets code per se although if you write the computer program in Java it should effectively be the same. This is something we are doing at my company to create a custom command interface for a product we have in development.
I want to connect an android mobile program to a C++ program, and i dont really know how it should be done.
I was thinking about a Bluetooth connection, but i dont really know how to handle bluetooth in C++. Could you give me some general advice about this?
If you think that i should use another kind of connection, like tpc-ip based, please, let me know and give me some general advices too.
I need the data transfer to be fast, because im trying to use the android device as an interactor, so i need a fast feedback from the C++ program.
Thanx.
If I were you, I would use a TCP/IP connection. It is very easy to implement in Java (Android) and also in C++. Besides, it makes it easy to change the frontend later on. And it is as fast as your network connection, which is usually faster than bluetooth.
Just make sure you put enough effort in the design of your protocol.
There are a lot of resources to be found on the internet on how to create TCP/IP connections, both in Java and C/C++.
If you wanted to have a client server model kind of an use here. Better is to host your Server app(Port your C++ app to Java servlets) & access the Server app via http via Android client. Webviews in android are very useful in doing these.
I need to develop an Android application that sets up connection via WiFi with computer and then sends packets with data. Jowever, I need to control send packets, not only theirs data but also headers, there should be possible to modify any field in their header as well. In windows in it is possible with use of winpcap and jpcap, and I wonder if sth similar I may find on Android. Is there any ready API that will help with my problem?
There's no API available to a Java/Dalvik app on Android which would allow you to do that.
Android is a Linux system, though. So you could try to find/write one or two Linux applications to support your effort - or use JNI.
Bottomline: Native code will definitely be necessary to achieve what you want, no way to do this in Java alone.