Retrieving geolocation in Java Web Start - java

I'm helping develop a Java Web Start* application and am looking for ways to retrieve the user's location. An ideal solution would be something like JSR-179 which uses the best available hardware, but failing that then interfacing more directly with GPS hardware (if available) is one possible option.
Has anyone out there implemented something like this, and if so what approach did you take?
Since I haven't been able to find any JSR-179-like APIs out there, I'm investigating a couple of potential solutions, but they both have drawbacks:
Read GPS data from a (virtual) serial port.
Would only support hardware which interfaced via a serial port.
As far as I'm aware we can't automatically detect which port to use, so would have to allow the user to configure this. This would be far from ideal!
Make use of HTML 5's Geolocation API, interfacing with it via the ScriptEngine API.
I've never used either of these before, so I've no idea how feasible this is at this point!
Can anyone suggest other potential approaches, or tell me if either of my ideas are dead-ends?
*Though we currently use Web Start, and would prefer to continue doing so, we might consider dropping that in favour of something like getdown if that would allow us to implement geolocation.
Edit:
An additional requirement I didn't originally state is that we need to be able to track the user's current location, not just the location they were at when they launched the app.

Instead of deploying your application as a Java Web Start application you could deploy it as an applet. In this case it becomes possible to call the browser API through LiveConnect.

The ScriptEngine API will not help you because it's not linked to the browser supporting the Geolocation API. Also, a Java Web Start is completely independent from the browser (you can close the browser and the application will keep working, unlike an applet), so it's not possible to call the Geolocation API.
A solution would be to provide the location parameter to the JWS application via an external mechanism that would use the HTML5 Geolocation API. For example, instead of calling directly the JNLP file for launching the application, you would load a page with a JavaScript snippet that query the Geolocation API and then call the URL of a JSP file:
http://www.example.com/myapp/launcher.jsp?latitude=....&longitude=....
The launcher.jsp page will generate the JNLP file with the appropriate parameters:
<resources>
<property name="jnlp.myapp.latitude" value="<%= request.getParameter("latitude") %>"/>
<property name="jnlp.myapp.longitude" value="<%= request.getParameter("longitude") %>"/>
</resources>
And you can then retrieve the coordinates in your application as system properties.
This will work if you are only interested in the static location of the user. If the user moves you won't be able to track him.

A question and idea more than an answer, but here goes.
What hardware are your users running on? I am guessing a laptop.
Could you insist that the user also has a smartphone and write a small app which would query their GPS position and report it to your main app?
(They may have smartphones already so this may not be an excessive requirement)
This reporting could be done by the phone uploading the position to a central db on the internet, and the app downloading that info, or it could be sent from the phone to the laptop wirelessly somehow.

Related

how to send post data continuosly to web and mobile

I am going to develop uber-like application.Here I have to send latitude and longitude to web and mobile devices continuously with my service,What I have do to get this.
Can anyone please give some idea.
You should start by designing how the application is to be used, seen from all the different users perspectives.
For instance is this a web app, or a native app, or both?
Then from that knowledge, you need to define a communication protocol.
You should be able to determine if the client will be polling for data, or if you need to push it from the server onto the clients.
This also goes for the data that travels the other way.
From here you choose a language for programming, and then start doing some proof of concept tests.
The choice will depend on the chosen underlying technologies
(web / native / os / available libraries)
After some test work you may have something that works, then you need to review or add security to the communication, cause we do not want everyone collecting location data from everyone that has the app installed.
Then run beta trials and eliminate the worst bugs, and then release the app.
You'll want some sort of asynchronous task which can get new data from your server and refresh the mobile and web content to reflect the content of the server. You'll also want to notify the server whenever you make local changes to content and want to reflect those changes. Android provides the SyncAdapter pattern as a way to easily solve this pattern. You'll need to register user accounts, and then Android will perform lots of magic for you, and allow you to automatically sync. Here's a good tutorial: http://www.c99.org/2010/01/23/writing-an-android-sync-provider-part-1/

Injecting items in Android browsers caches

I am currently trying to find a way to programatically inject items into a mobile browser's cach on Android devices. The browser type doesn't matter, it can be Firefox, Chrome, Android's built in browser, etc.. Is there any documentation or examples of ways to programatically inject objects into the browsers of Android devices?
Not really an answer, just a heads up. Seeing that your question is tagged java, I assume you want to do this from an application, and not from the browser. I'm pretty sure that's impossible, because each Android app is running in it's sandbox. Communication between apps is done through Intents and IPC. In both cases, you are limited by what the target app is offering support for.
You can use proxy, to get this structure :
Client => Your APK => Server
(Like this application).
With your APK you can choose file to send.
Like already mentioned by Corneliu, its impossible for an normal android app to write into the data section of another app.
Although it should work when the phone is rooted. Apps like TitaniumBackup which require root can read and write the data saved by other apps. You can use TianiumBackup to make a backup of the browsers and look in the *.tar.gz file for the internal data structures and the SQLite DB files...

How do I connect my Desktop Java Application to an Existing GAE Datastore?

Currently I have a very basic desktop Java application in Eclipse that is meant to add entities to an existing project's datastore on Google App Engine. I have it all setup right now but since I am new to working with Google App Engine, I have no clue on how to get the application to send the Entities into the datastore of my existing project.
I tried looking this up online but most of what I found was for making java web apps. My goal is to have the application running as its own application, not through a browser.
So, what do I have to do to make the application connect to my GAE datastore? Is there some code I need to type, or perhaps some xml file I need to have within the project? I am just using the Java Eclipse plugin for Google App Engine.
Thanks for the help!
Based on the language of your question, I think you really need a big-picture sort of answer, rather than any specific code. Therefore:
You have a desktop application. This runs on some desktop computer.
You have a Google App Engine application with its data store. This runs in Google's data centers.
These are not the same computer. Therefore, they must communicate over the network in some fashion — that is the missing piece you're looking for.
Since GAE is designed around doing web applications, I recommend you think of this as a “web service” situation — that is, your desktop application makes HTTP requests to your GAE application. (The situation is simplified over the general case because you are writing both the client and the server.)
I recommend you read about designing simple web services and do whatever seems to fit your application.
One important warning: Unless your GAE application only ever has one user, you must not simply write a bridge that gives access to the data store over HTTP, because then anyone can make arbitrary changes to other people's data. As it is said for multiplayer game design: don't trust the client — that is, only accept network requests that make sense according to the rules of your application, and do not expect the client to enforce those rules. This is because anyone can make requests to your GAE application using something other than your desktop application, so you must assume you could receive arbitrary requests. This is the fundamental nature of the Internet.
For example, in the simple case of a multi-user application whose users do not interact with each other using the application, this means that every request that, say, updates a record, should only update a record which belongs to the logged-in user, not one of any other user.
For anyone that gets this problem in the future, I got an answer to it. I just tried experimenting around with the project settings and found it. So as it turns out, after you have installed the GAE Eclipse Plugin, you can just right click your project folder in the Package Explorer, go the Google sub menu, then click on App Engine Settings... .
From there, you need to check the Use Google App Engine checkbox, then in the deployment section, just fill in your project's Application ID. Your project's application ID can be found under the Application Settings tab of your project's online Google app engine dashboard. It is listed there as your Application Identifier.
Turns out that for me, I will need to find a different solution as you cannot integrate GAE with a desktop application that uses the Java Swing library. Bummer :/

I want to use Google Map API for my Desktop application

I want to use google map API for my desktop application. The application will be totally connected to the internet.
While I was searching some research notes about this implementation. I found a ideal site with the configurations, but it has some java files to be downloaded, but when I tried that website its not loading. which is swinglabs.org
http://today.java.net/pub/a/today/2007/10/30/building-maps-into-swing-app-with-jxmapviewer.html
Any other options of doing this api implementation to my desktop application? and one more thing. I tried downloading the google api. even it ask a url.We have to provide a url then only we get a key to download it. And the api should run in that specific url. Otherwise, its not working. How this appears to a desktop application
any ideas welcome.
At the moment it is illegal to use the JXMapViewer with google maps, reason being that this component requires direct access to Google's tile server. According to Google's ToC:
Can I access the Maps and Satellite
images directly?
You may not access
the maps or satellite images through
any mechanism besides the Google Maps
APIs (such as the creation of your own
mapping API or the use of a bulk tile
download script). Your application's
access to the tiles will be blocked if
it accesses them outside of the Google
Maps APIs. See section 5.3 of the
Google Terms of Use for more details.
More information can be found here. You should be able to download the packages from here. They moved the domain and many sites still point to the old domain, hence taking you nowhere.
Currently the only way you can use the JXMapViewer by displaying maps from OpenStreetMap.
You can, however, display static maps on your application. You basically build a URL. This tutorial should give you a basic idea on how to be able to build a URL to be able to request static maps. You then use an HTTP Get request to get the image back.
Last but not least, Google is planning on allowing direct access to their tile servers, but this might take a while.
You can use google maps in desktop applications.
For this you need to embed a browser in your application and then open up html/javascript files which render a map.
Different languages and api provide ways to embed a browser. For example wxwidgets/c++ has a widget called WebView which allows to embed webkit on linux and trident on windows. Similary mfc/c# also allow the same. So checkout how to embed a browser into your application.
The api should also provide a way to execute javascript code in the embedded browser. Then you can modify the google map through the code of the application as and when needed.
I have a desktop application that calls a similar API. They require the API calls to come from one particular domain (and URL). So, I have the desktop app contact my own web server, which calls the third party API and returns the results.

Connect two calls via web application

I need to add a functionality to my java-based web application that will allow users to click on a link and the application will automatically call the user and another party and connect them in a phone call.
Does anybody know what would this entail?
Thanks
It can be done with Twilio, and their new, easy Conferencing API. Trust me, it's really really simple. Another option might be CloudVox, but I haven't (formally) tried their service yet.
The World-Wide Web Consortium has an integrated set of speech interaction standards that you'll find interesting. There's a markup language called VoiceXML that is analogous to HTML in that web applications generate it. It differs from HTML in that it's specialized for temporally-based speech interactions instead of visual interactions. So instead of looking at a screen you listen to audio prompts and computer-generated speech. Instead of typing and mousing, you speak back and what you say is processed by a speech recognizer or recorded.
There are many companies using VoiceXML to automate voice response systems, and they handle billions of calls per year. You've probably talked to them many times without realizing it. One of the best companies in this space is Voxeo, and they have a developer site at http://evolution.voxeo.com/ that you can play with. Evolution lets you call your web application over an ordinary phone (or Skype). You actually talk to a VoiceXML-based web browser which will fetch a VoiceXML page from your Java application server, "play" it to you, listen to what you say, and then report that back to your app via a form submission, get the next page to render to you, etc.
Another related standard is CCXML, or Call Control XML. You use this to create teleconferences that may or may not include a voice response application.
So it sounds like in your case you want your standard web application to talk to a CCXML server and ask it establish call legs to the web user and to a customer service line. I know that Voxeo Evolution offers CCXML as well.
There are other good companies in this space too. One that comes to mind is TellMe, which was bought by Microsoft a year or two ago. These two companies (and others) offer professional services too.
So I wanted to write this up as an answer to the comment above. The Skype API provides a number of options for telephony in COM, Java and Python:
Skype4Java - https://developer.skype.com/wiki/Java_API
Skype4Py - https://developer.skype.com/wiki/Skype4Py
Skype4COM - https://developer.skype.com/Docs/Skype4COM
They provide a communication and command protocol layer for working with Skype, more info on the API here:
https://developer.skype.com/Docs/ApiDoc/Overview_of_the_Skype_API
It's kind of different for every platform, the Linux version is based on DBus or X11.
Try FreeSWITCH. I have done this before. Its pretty straight forward. Can be a bit hairy when you need to log call accounting and all those stuff. I hopefully would be able to provide you some guidelines and code samples, let me get home first. Cheers.
The good thing in using FreeSWITCH, you will be able to handle multiple calls, and quite a number of. You might need that in future.
Note: You have to use some kind of VoIP provider in order to do that. I was using Gizmo5 that time and it was pretty good.
Sorry buddy, lost the servlet code somewhere. But no worries it was a simple servlet. Fortunately, I had added my example Java code for XML-RPC, into the FreeSWITCH wiki, and actually that was the code my servlet was invoking down the road. Below is the snippet.
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
XmlRpcClient client = new XmlRpcClient();
try {
config.setServerURL(new URL("http://localhost:8080/RPC2"));
config.setBasicUserName("freeswitch");
config.setBasicPassword("works");
client.setConfig(config);
// For external phone calls using VoIP. We will use something like below.
// new Object[]{"originate", "sofia/gateway/gizmo1/6098989898 &bridge(sofia/gateway/gizmo9/0116054545454)"}
// gizmo1, and gizmo9 are the accounts configured under freeswitch gateway configuration.
client.execute("freeswitch.api", new Object[]{"originate", "sofia/internal/1001 &park()"});
} catch (Exception ex) {
ex.printStackTrace();
}
Moreover, you need to configure few things prior doing this. You need to set up the gateway using your VoIP provider settings.
For FreeSWITCH related help, take a look at this SO Thread.
I know of 2 API providers that does what you need:
1) twilio - can connect to 2 or more parties using TwiML (their markup). example
2) Hoiio - very easy to use with 1 line of RESTful api call. example

Categories

Resources