Hi,
Thanks for sharing this work, maybe someone could clean it and merge it into python-for-android, then add it in the pyjnius documentation?
Anyway, that's cool to see a working GPS example :)
Good work!
Mathieu
Hello Mathieu.I'm Angel, and I'm a happy boy since using Kivy.I've seen kivy about 1 year, but I haven't used because of lack of BT and GPS for my android (and future iOs) projects....But this is old problem, in new version we can use both, thanks to your work (and friends...) ;-)I've seen pyjnius and it's promissing....Some tests I've done (and working):FOR BT (without using java at all):# Bluetooth partBluetoothAdapter = autoclass('android.bluetooth.BluetoothAdapter')BluetoothDevice = autoclass('android.bluetooth.BluetoothDevice')UUID = autoclass('java.util.UUID')btAdapter = BluetoothAdapter.getDefaultAdapter()if btAdapter.isEnabled():print 'enabled'btdevices = btAdapter.getBondedDevices()for i in btdevices.toArray():a = i.getAddress()device = btAdapter.getRemoteDevice( a )socket = device.createRfcommSocketToServiceRecord( UUID.fromString( "00001101-0000-1000-8000-00805F9B34FB" ) )try:socket.connect()except:print 'BAD connection'else:# We don't have bt, try to enable and later re-try using...print 'disabled'intent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)currentActivity = cast('android.app.Activity', PythonActivity.mActivity)currentActivity.startActivity(intent)#intent = Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE)#currentActivity.startActivity(intent)
For GPS (some harder, excuse my programming, I'm a dumb java programmer)KivyGps.java (in renpy/android as you say in doc)package org.renpy.android;//import java.util.ArrayList;//import java.util.List;import android.location.Location;import android.location.LocationListener;import android.location.LocationManager;import android.content.Context;import android.os.Bundle;import android.os.Looper;import java.lang.Thread;import android.app.Activity;public class KivyGps {LocationManager lm;Thread gpsThread;public long minDistance = 1;public int minTime = 1000;static class KivyLocationListener implements LocationListener {public Location lastLocation = new Location("Other");//private List<LocationListener> listeners = new ArrayList<LocationListener>();public void onLocationChanged(Location location) {// TODO Auto-generated method stublastLocation = location;//updateListeners(location);}public void onProviderDisabled(String provider) {// TODO Auto-generated method stub}public void onProviderEnabled(String provider) {// TODO Auto-generated method stub}public void onStatusChanged(String provider, int status, Bundle extras) {// TODO Auto-generated method stub}public Location getCurrentLocation() {// TODO Auto-generated method stubreturn lastLocation;}}static public KivyLocationListener locationListener = new KivyLocationListener();public Thread init(final Activity currActivity) {gpsThread = new Thread( new Runnable() {public void run() {try {Looper.prepare();lm = (LocationManager) currActivity.getSystemService( Context.LOCATION_SERVICE );lm.requestLocationUpdates( LocationManager.GPS_PROVIDER, minTime, minDistance, locationListener );Looper.loop();}catch ( Exception e ) {e.printStackTrace();}}} );return gpsThread;}//gpsThread.start();}Using in python:LocationListener = autoclass('android.location.LocationListener')LocationManager = autoclass('android.location.LocationManager')LocationProvider = autoclass('android.location.LocationProvider')Location = autoclass('android.location.Location')Looper = autoclass('android.os.Looper')Context = autoclass('android.content.Context')KivyGps = autoclass('org.renpy.android.KivyGps')currentActivity = cast('android.app.Activity', PythonActivity.mActivity)lm = currentActivity.getSystemService( Context.LOCATION_SERVICE)if lm.isProviderEnabled( LocationManager.GPS_PROVIDER ):print 'CON GPS'else:print 'SIN GPS'lps = lm.getAllProviders()for lp in lps.toArray():print lp#Arreglar problema de derechos ACCESS_FINE_LOCATION en Kivy Launcherlp = lm.getProvider('gps')ll = KivyGps.locationListenerkgps = KivyGps()gpsThread = kgps.init( currentActivity )gpsThread.start()loc = ll.getCurrentLocation()if loc:print loc.getLatitude()print loc.getLongitude()Best Regards.Angel Maza.
There is some bug in the android system using bluetooth SPP with BT modules in market...
--You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/n_cMbFzf_1A/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
--
You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/n_cMbFzf_1A/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.