Java Library in Android Project - java

I want to make a java library (so I can compile it into a jar) that makes calls to a server. I then want to share this amongst android application projects so that I can access those simple calls.
Is using HTTPRequest the best way to do this?
http://docs.oracle.com/javase/7/docs/api/java/net/HttpURLConnection.html
Something about making web calls in the java way and sharing them in android apps seems odd to me. should this be an Android Library instead? (I believe those should only be used when resources are involved)
Sorry for the potentially simple question.

You can develop a common Java library that you can use with both android , and regular java projects.
Take a look at OkHttp , it shows you how to achieve this. It is related to HTTP client, may be it already provides everything you need. You can extend it where needed.
For a simpler example (~20 java classes), take look at Okio , the underlying io library used by OkHttp.

Related

Android VoIP call implementation

First of all I'm a newbie in VoIP implementation. I need to implement VoIP single and group call in android application. Could you tell me, what is actually the best way to achieve this ? I'm looking for Android SIP library (probably open source) which should:
has good documentation with simple app examples
be ready to use with java
Maybe just native android SIP api will be the best ? But I heard that it doesn't support group calls.
Most of the voip libraries use C/C++ implementation for various reasons. You can use PJSip which is a C voip/sip stack. It has a good documentation but you have to build it yourself using android ndk . It has good documentation and also contains processes to build it for Android and other platforms. But there is no java/android wrapping built in so you should do that yourself. Another option is Liblinphone which is also based on C stack but provides all of the wrapping and implementations out of the box so you don't have to bother so much on native codes. It also has a sample application which you can try yourself. One downside of Liblinphone is that it lacks proper documentation and you have to dig in more.
Regarding the android SIP api, I don't think it is a good option as it has much more limitation and hardly maintained. It is based on Jainsip stack which is a 100% java stack but is too verbose. I personally would like to recomment Liblinphone as I am currently implementing it and am pretty satisfied with it. Best of luck...
Update
Here is the source code of linphone for android if you are interested in it. You can get pretty much idea of Liblinphone for android from it. You have to dig much more into the sources though.
You can have a look at Restcomm Android SDK:
It's open source, with an active community around it
It using SIP for signaling and Webrtc for media so should work nicely with NATs, etc
Comes with 2 sample applications that you can play with and alter their code to experiment
Comes with quick start guide, reference doc
You can check the Olympus sample App right away by installing the .apk from this link
Notice that the SDK doesn't support group calling out of the box, but you could combine it with Restcomm-Connect open source platform to add such functionality very easily. Restcomm-Connect also comes with docker, so you should be able to install it right away.
Please let me know if you have any questions
Best regards,
Antonis

how similar is the language used for android SDK to java?

is there a point starting with java basisc or should I go for android-based examples and tutorials?
They are basically the same. But, I recommend going with android based examples since android has unique app cycle and app format.
Android SDK is build in and using Java.
They are for all intents and purposes the same.
However Android is coded using it's own specific library methods and syntax, hence it's a better idea to skip directly to Android. Knowing Java makes it easier but is not a necessity to code in Android.
You will require the JDK since it does need Java to run.

Create Android library jar to work with non-Android project

I am working on a library that ideally will have a strictly-Java component and added functionality for Android-specific projects, with the intent to be most useful for Android apps, but also work with other Java apps.
But my question is: how should this be designed? I do not plan on needing resources, so I want to compile it into a JAR, but would I need to make two JARs, one of the Java stuff and another for the Android stuff? Or would a Java-only application be able to use a single JAR so long as it does not use the Android components?
If you make a library that uses pure java and does not use any android apis. It will work on both standard java and android java. However if the library uses any android apis it can't be used in a standard java project.
As far as I know, the JAR would be good for both types of aplications. It seems to mee that both JARs (just Java and android) are totally identical and thus equally compatible. If you don't use any of the android components, including Resources there should not be a problem at all.
You should still check whether you depend on libraries which are available on android and any normal Java distribution or -if not- either tell the user to preinstall the depending libraries or ship them whitin your JAR package and build path. Be carefull not to use libraries which are not available on android because the user has no or really few options to install them on himself.
What I don't understand is why you think your library is more usefull to android developers. I can not think of any example where this could happen. If the problem is really specific for android, you should consider developing the library android-only. If the problem is more general the lib will be usefull to all developers that might come to this problem, not just android.

Difference between Kivy and Java for android apps

I'm a python developer with little experience creating android apps in java and want to create an app that will access my university web portal, retrieve some data and show on a view.
So, after researching Kivy, I have a few questions:
1) Which one is easier and faster to develop android apps?
2) Does Kivy have any android feature limitations?
3) And finally, would an android app developed using kivy run as fast as one developed using java?
This is a rather subjective question.
1) Which one its easier and faster to develop android apps?
I think there's a strong argument for kivy, but this doesn't have an objective answer.
2) Does Kivy has limitations to access certain parts of android (like not fully integrated with its api)?
The kivy project includes pyjnius, a tool for accessing java classes through python, and in principle I think this should give arbitrary (edit: on reflection, not arbitrary, but probably not limited in immediately important ways) access to the java apis.
In practice, prebuilt python wrappers are a work in progress, though rapidly improving. The android python library already gives easy access to many things (including but not limited to intents, vibration, accelerometer etc.). Even where there isn't already a python wrapper, it can be very easy to do the necessary work.
Edit: There has recently been great work on Kivy's plyer project, intended to provide a transparent api to platform specific tools so that you can call it once and get the same behaviour on different systems without knowing about the details. It includes useful support for parts of the android api.
3) And finally, an android app developed using kivy would run as fast as one developed using java?
Ultimately the answer is probably no, but the difference is highly unlikely to be important unless you're doing something strongly cpu limited. The task you suggest would not be limited in that way.
To complete inclement's answer, pyjnius indeed allows to access a lot of the android api. But it's not perfect, calling existing classes is not always enough, and an android programmer often need to create code that will be called by android to manage events, there are two ways to do that, both used by the android api.
The first one is interfaces: you need to create a class that implement an existing java interface, pyjnius can do that, you create a python class and declare which java interface it implements, and have a decorator to declare the methods you have to declare.
The second is subclassing, you need to subclass an existing java class and override some methods, and we don't have a way to do that with pyjnius yet, so for these ones, you'd have to create a java class and use it in your program (fortunately you can mix that with kivy/pyjnius, it's just can't be 100% python in that scenario).
So it can be worth a look to the api beforehand, to see if the parts of the android api you have to access requires that.

Create Android apps in Eclipse sharing common library

is it possible to create java libraries the apps can use shared?
It is totally clear to me how to create a library project and how to use it while shared between several another projects, compile each project into different apps.
But in this case the library gets compiled into each app separated.
What I want is to create a library, compile it, install it into the device (or emulator) and several apps calling into this library.
And when it is needed to change something the apps use shard in this library, I just re-work the library, re-compile it, replace it on device (or emulator), and the apps use the new library, all apps use the new functions.
Is it possible?
I googled it, but I couldn't find the solution.
I am using Win + Eclipse, I can't use native code (since I know only Java).
Thanks
UPDATE: Thank you for your suggestions, I know about using Services and Activities started explicitly in order to share functionality.
I asked about libraries because I am investigating the possibilites. If there is no way to use common library, what is the purpose of uses-library... in the app manifest?
Thank you
It's more likely that you need a service as a library. Have you considered this possibility? You can create it as a separate application, define an interface for your service and use it in other apps. So as the interface does not change this will not influence on other apps that depends on this service.
The Android model installs each application as a separate user (UID) on the device and the users have no access to other application's/user's files. Therefore, you can't share libraries as such.
As Yury suggested, you might need a service or an activity that can be invoked from multiple applications.

Categories