<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div><span>Great !</span></div><div><span>Please let me know when you have something.</span></div><div><br><span></span></div><div><span>Cheers,</span></div><div><span>BogDan.<br></span></div><div><span></span></div><div><br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><div style="font-family: times new roman, new york, times, serif; font-size: 12pt;"><div style="font-family: times new roman, new york, times, serif; font-size: 12pt;"><font face="Arial" size="2"><hr size="1"><b><span style="font-weight:bold;">From:</span></b> Frameworks <frameworks@qlands.com><br><b><span style="font-weight: bold;">To:</span></b> <br><b><span style="font-weight: bold;">Cc:</span></b> "necessitas-devel@kde.org" <necessitas-devel@kde.org><br><b><span style="font-weight:
bold;">Sent:</span></b> Thursday, June 2, 2011 8:10 PM<br><b><span style="font-weight: bold;">Subject:</span></b> Re: GPS service for android and suggested changes in Necessitas.<br></font><br>
Hi,<br><br>No problem.<br><br>I am working on the GPS mobility plug-in (giving that there is a way of <br>having the JObject of the current activity running the QT application).<br><br>Cheers,<br>Carlos.<br><br>On 06/01/2011 09:53 PM, BogDan wrote:<br>> Hi,<br>><br>><br>> Please accept my apologize for slow replay.<br>><br>> <br>>> ________________________________<br>>> From: "<a ymailto="mailto:frameworks@qlands.com" href="mailto:frameworks@qlands.com">frameworks@qlands.com</a>"<<a ymailto="mailto:frameworks@qlands.com" href="mailto:frameworks@qlands.com">frameworks@qlands.com</a>><br>>> To: <a ymailto="mailto:necessitas-devel@kde.org" href="mailto:necessitas-devel@kde.org">necessitas-devel@kde.org</a><br>>> Sent: Sunday, May 29, 2011 10:58 AM<br>>> Subject: GPS service for android and suggested changes in Necessitas.<br>>><br>>><br>>><br>>>
Hi,<br>>><br>>><br>>><br>>> First of all. Thanks for the brilliant work!.... Running QT in Android is just mind-blowing!<br>>><br>>><br>>> I just joined the list of developers to contribute to the project. Just after I got a copy of Necessitas 0.1 I had to see how to make the GPS work. I wanted to implement it as most as possible with JNI and with the minimum of java code.<br>>> <br>> Great, we have something in common :)<br>><br>><br>> <br>>> From a GPS example written in Java (http://hejp.co.uk/android/android-gps-example/) I got that the main challenges were:<br>>> 1- To implement the LocationListener interface<br>>> 2- To connect to the location manager by Activity.getSystemService(service)<br>>> 3- To request the locations using the Listener by LocationManager.requestLocationUpdates(gps provider, double, float,
listener,looper)<br>>><br>>> This main challenges arose from two main constraints:<br>>> 1- The LocationListener is an interface so needs to be implemented in a class in a very basic way. Thus I had to include such implementation as part of the industrius java classes: QtGPSListener.java with the following implementation:<br>>><br>>> package eu.licentia.necessitas.industrius;<br>>> import android.location.Location;<br>>> import android.location.LocationListener;<br>>> import android.location.LocationProvider;<br>>> import android.os.Bundle;<br>>> <br>>> public class QtGPSListener implements LocationListener {<br>>> <br>>> public void onLocationChanged(Location location)<br>>> {<br>>> // Here we get the location data and
create a result<br>>> // string (A really basic way of passing data). We called sndonLocationChanged that is<br>>> // in fact connected to the qt application by JNI's registeNatives<br>>> String accuracy;<br>>> accuracy = String.valueOf(location.getAccuracy());<br>>> <br>>> String altitude;<br>>> altitude = String.valueOf(location.getAltitude());<br>>> <br>>> String latitude;<br>>> latitude =
String.valueOf(location.getLatitude());<br>>> <br>>> String longitude;<br>>> longitude = String.valueOf(location.getLongitude());<br>>> <br>>> String res;<br>>> <br>>> res = "|AC:" + accuracy;<br>>> res = res + "|AL:" + altitude;<br>>> res = res + "|LA:" + latitude;<br>>> res = res + "|LO:" + longitude + "|";<br>>> <br>>> sndonLocationChanged(res);<br>>>
}<br>>> <br>>> <br>>> public void onProviderDisabled(String provider) <br>>> {<br>>> String res;<br>>> res = "Provider " + provider + " is disabled";<br>>> sndonProviderDisabled(res);<br>>> }<br>>> <br>>> <br>>> public void onProviderEnabled(String provider) <br>>> {<br>>> String res;<br>>> res = "Provider " + provider + " is enabled";<br>>> sndonProviderEnabled(res);<br>>> }<br>>> <br>>>
<br>>> public void onStatusChanged(String provider, int status, Bundle extras) <br>>> {<br>>> switch (status) {<br>>> case LocationProvider.OUT_OF_SERVICE:<br>>> sndonStatusChanged("Status Changed: Out of Service");<br>>> <br>>> break;<br>>> case LocationProvider.TEMPORARILY_UNAVAILABLE:<br>>> sndonStatusChanged("Status Changed: Temporarily Unavailable");<br>>> <br>>> break;<br>>>
case LocationProvider.AVAILABLE:<br>>> sndonStatusChanged("Status Changed: Available");<br>>> <br>>> break;<br>>> }<br>>> <br>>> }<br>>> // List of methods that will be linked in the qt application<br>>> // using JNI's registerNatives<br>>> public static native void sndonLocationChanged(String currLocation);<br>>> public static native void sndonProviderDisabled(String message);<br>>> public static native void sndonProviderEnabled(String message);<br>>>
public static native void sndonStatusChanged(String message);<br>>> <br>>> }<br>>><br>>> 2- I had to use the activity running the qt application so I can use getSystemService(String). I though there were some Android API to get an instance to the current activity running (so I can use JNI to get it) but it seems that there is none.<br>>> <br>> Actually it is, QtApplication.mainActivity()<br>><br>><br>> <br>>> So the only alternative that I had was to pass the activity from QtApplication.java to qtmain_android.cpp. For this I made the following changes:<br>>> <br>>> 2.1 - In QtApplication.java: FROM: public static native void startQtApp(String params,String env) TO: public static native void startQtApp(String params,String env,Object currAct)<br>>> 2.2 - In qtmain_android.cpp: FROM: static jboolean
startQtApp(JNIEnv* env, jobject /*object*/, jstring paramsString, jstring environmentString) TO: tatic jboolean startQtApp(JNIEnv* env, jobject /*object*/, jstring paramsString, jstring environmentString,jobject currAct)<br>>> 2.3 - In qtmain_android.cpp: I created a jobject currActivity = NULL that I can extern in my sample application. Plus assigning it a global reference of the current activity: currActivity = env->NewGlobalRef(currAct). This to use it in JNI thread of execution<br>>><br>>> <br>> Hmm :)<br>><br>><br>> <br>>> With this changes I create a QT GPS class with JNI code that access the GPS. I just need to pass it the JavaVM that I extern from qtmain_android.cpp and currActivity.<br>>><br>>><br>>> I can see that in 0.2 necessitas include QtLocation.java (which implements the GPS). Although it is fine, I reckon it is better
to implement much of that code in the c++ side with JNI and only have the minimum java code just for implementing interfaces for example.<br>>><br>>> <br>> Agree with you !<br>><br>><br>> <br>>> This is an snapshot of the QT GPS class where it connects to the service<br>>><br>>><br>>> <br>> [...]<br>><br>> <br>>> To conclude. A JNI implementation of the Android GPS service with very basic java code will require to have a Jobject pointing to the current activity running the QT application.<br>>> <br>> Please call QtApplication.mainActivity() to get it !<br>><br>><br>> <br>>> This I reckon would make a Mobility plugin less dependent on external java coding.<br>>> <br>> It will be great, because the java part can't be updated, by Ministro
service !<br>><br>><br>> <br>>> But where it would be the best place to implement this change? I made it on qtmain_android.cpp and qtApplication.java but for a Mobility plugin this might not be the case.<br>>><br>>> <br>> Please change current Mobility implementation ! You'll get Java_vm pointer when the plugin is loaded by application and QtApplication.mainActivity() is a static function which can be used to get current activity.<br>><br>><br>> <br>>> I register myself on gitorious. For contributing do I need to work on a clone of master?<br>>><br>>> <br>> Please clone http://qt.gitorious.org/~taipan/qt-mobility/android-qt-mobility and use testing branch !<br>><br>><br>> <br>>><br>>> Thanks a lot for the brilliant work!<br>>><br>>><br>>><br>>>
<br>> Thanks,<br>><br>> I'm looking forward to hearing from you<br>><br>> Cheers,<br>> BogDan.<br>><br>><br>> Again, sorry for slow replay.<br>><br>><br>> <br><br>_______________________________________________<br>Necessitas-devel mailing list<br><a ymailto="mailto:Necessitas-devel@kde.org" href="mailto:Necessitas-devel@kde.org">Necessitas-devel@kde.org</a><br><a href="https://mail.kde.org/mailman/listinfo/necessitas-devel" target="_blank">https://mail.kde.org/mailman/listinfo/necessitas-devel</a><br><br><br></div></div></blockquote></div></div></body></html>