C# to Java for android - java

I am creating a program for android that will act as an email client. Problem is there is a specific type of protocol that doesn't work with Java, at least I haven't been able to find a way to get it to work. So, I have downloaded xamarin and am coding the methods in c# because this protocol is native to c#. My question is can I then somehow turn this c# code into a library or module that I can call from my java android app that will handle the methods that don't work in java using the c# code?

I think your best route (being an android application) would be to consume a c# api with your java code. Other options include passing serialized objects through xml or json and trying to get j# to work with java to allow your c# to pass through IL to J# and then have that sent through to java.

Related

c# classLibrary.dll to be used in android studio/ android app

This is kind of a general question but anyway:
In c# I have made a class library(api) which works on windows systems. I am now looking into making an api with the same functionalityies for android. One of the functionalityes (streming data from custom bluetuth device) needs to be written in java. So (in android studio) I have written a java class to do that, compiled a .jar and tested it in Unity as a plugin. But to avoid translating a ton of c# code into java I am now wondering if it is possible to somehow import a c# api into android studio and just call it's methods from java classes( as you can do in Unity's.Monobehaviour (AndroidJavaClass.Call("functionName", object[]parameters)) or maybe as you can do wit .jar-s code in VisualStudio(IVKM.Net. IVKM.NET))? To put it as plainly as possible: I would like to convert a api.dll to api.jar.
If you can suggest another alternative solution, please do so.
Thanks.
Havent tried, but will try hinting towards C++ support in Android with Native development Kit by converting C# to C++ code, as in .net all of your code is CLI code anyways, so it should be convertible to some barely readable C++ surogate code which should compile just fine.
https://www.quora.com/Can-we-use-C++-and-Java-together-in-Android-Studio
Hope this helps!

How to create REST API backend using parse.com in Java?

I'm sort of new to http://www.parse.com . And I want to develop backend in Java using REST API. It seems parse.com does not provides direct Java library for REST API development. But I found some third party libraries(un-official) like for Java:
JAVA
Almonds — A Java REST API that mimics the Android API.
mobile-parse-api — This library implements the REST API of parse.com in java with open interfaces for libgdx and playN.
Parse4J — Library for the REST API.
ParseFacade — Parse Android SDK alternative.
But I am not understainding how to get start with these libraries in order to create backend API in Java
#Mahendra
I assume by now you have found your answer. In case you haven't then here is a thought process that might be of interest.
From the little reading I have done on Parse.com it is a sort of like an Object database in itself which provides ready REST style api for all data stored there. See this - https://parse.com/docs/rest/guide
In addition they provide libraries for all popular Front Ends (iOS, Android, JS).
I think they are advocating a paradigm shift for programmers who are used to having a lot of processing on the Backend servers and exposing simpler rest API which provides a processed and targeted response to each http request.
Basically they are suggesting that the whole backend infrastructure (db, app server, server side logic etc) can be replaced by parse.com
If you are considering using Parse.com I assume you have read and understood above mentioned thought process and decided that it makes sense for your project.
I would advise you to consider using a using a common client side Java library that works with the Parse rest api and then use appropriate Client SDK (iOS, Java, JS etc) to work with your library and design the UI. Since you are asking about Java library, I assume your language of choice for storing processing logic is Java.
What I suggest next may be bit of a long shot ... but worth a consideration.
Write code non-ui code in Java and work with the Android API from Parse.com. Use a Java to Objective C. https://github.com/google/j2objc
This will also allow you to use Java code for your web browser (using GWT as a UI framework).
Then write UI code in the framework suited for the platform (obj c for ios, Java for Android, GWT + Java for web browsers) and use the java library to connect to Parse.com.
If you have already tried out such an approach would be good to write back opinions in a comment so the community may benefit.

Does RoboVM convert swing java apps?

I have looked and I cant find the answer. Id like to know before i begin this project, but does RoboVM convert java directly to iOS aka objC? Does this work for both Java and Android? Does this also include java Swing? Im wondering if I can convert my java game directly to iOS. Thanks,
RoboVM converts what you have in Java into bytecode that will run on iOS.
You can't run Android-specific code (anything that has "android" in the import) on iOS, so you will have to add iOS methods that do similar things. Generally you create an Interface that asks the "native client" to do something, and then the Android or iOS code handles the request for the current native client.
Java Swing should work, although I have not tried it personally.

android use pcap library

I have a general question according an android app, I need to use some pcap functionality in my android app. Because java does not give the possibility in raw packet injections and low layer programming (as far as I know, pls correct me if I'm wrong) so I was looking for an alternative. So far I found the following:
ANDROID NDK
JNETPCAP
Any suggestions which one I should use or does anyone have other suggestions?
The JNI Solution
You need to wrap the calls and the logic you need out of libpcap in C or C++ and expose the underlying functions through JNI (Java Native Interface) so your application can call native code in Java.
The documentation on JNI is pretty complete on internet, a lot of tutorials exists on this subject such as this one.
If you want to easily wrap native code in JNI you can use Swig which allow you to automatically generate JNI code based on your C/C++ native headers.
The obtained JNI code should be compiled using the Android NDK as a dynamic library (.so). This library is to be placed in your application package under libs/. You can then invoke System.loadLibrary(path_to_you_dynamic_library) to load all the symbols contained in the library and use them in Java.
Using a third-party library
If you're afraid of getting headaches while figuring out how to use JNI, you can look at this library which does the hard work for you, and provides an API to manipulate raw sockets in Java.
http://www.savarese.com/software/rocksaw/
You need to wrap the calls and the logic you need out of libpcap in C or C++ and expose the underlying functions through JNI (Java Native Interface) so your application can call native code in Java.
Or you need to get a library that's already done that, such as, err, umm, jNetPcap.
One problem you may have with any attempt to do packet capture on Android - or any other OS using the Linux kernel - is that, by default, the underlying kernel mechanism used by libpcap (PF_PACKET sockets) requires root privileges. If there's a way to run your code as root, or to give it CAP_NET_RAW and possibly CAP_NET_ADMIN privileges, it might be possible to make it work.

how to use java code from .net desktop application?

I want to Use Some Java Code From the WCF Service. Basically I need to intreact with the java application from the .net so how can I make it out for that? Any guidance for that?
I was just wondering that how can i call java code from my .net desktop application? Do I need to create .exe file of my java poject or jar? How would I invoke that java project from my .net desktop application?
Like some code in .net desktopp application will call
void startprocessing ();
code written in java application
Let me Clear the Things What i want to implement..
I have one desktop appplication of windows and I want to integrate my speech recgnition facility in that application which is in java. What I want is to exchange the audio data as binary and some strings from .net application to my java application so I can process on that binary data to convert wav file and etc and recginze it..that is just completed ..but what I need to know is how to send those strings and some binary data to java application and just invoke that java application ?? Do I need to 'use'(?) wcf or other service ?
Going out on a limb here, sounds like you java app needs to expose the method you want to call via a web-service. That's of course assuming you have control over that in terms of the java app you're interacting with. Not sure though you can access that method simply by compiling your java app to native.
You can take a look at JNBridge, which provides interop possibilities between Java and .NET. However, as another poster has suggested, exposing the functionality through a web service is probably a better solution.
A quick Google search will give you plenty of information on how to create web services in Java, but for starters you can take a look at: http://docs.oracle.com/javaee/6/tutorial/doc/bnayl.html
I have Successfully done that with the axis 2 webservice with tomcat apache server with the following link..its too easy .i really got succeeded
http://blog.sencide.com/2011/06/create-web-service-using-apache-axis2.html

Categories