Note that there are some explanatory texts on larger screens.

plurals
  1. POError on getting gps location
    text
    copied!<p>I'm developing an app that communicates with three remote services on my phone. For the communication i'm trying to figure out which method is the best (intents or AIDL). I receive a stream via bluetooth in a rate of 4 streams/second with 15 bytes each and now i want to add my gps location in order to execute data logging. I need my gps location every second. Since the time in requestLocationUpdates is just a hint, i created a timer which asks for the last known location every second.</p> <p>Unfortunately I'm getting an error that I can't fix when i try to communicate using AIDL. The strange of this is, when i'm using intents to pass the received data to the remote services all works fine.</p> <p>Can anyone help me out ?</p> <p>Here my code:</p> <pre><code> private static final long MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 0; //meters private static final long MINIMUM_TIME_BETWEEN_UPDATES = 1000; //in Milliseconds private final MyLocationListener listener; private final LocationManager mLocationManager; private final List&lt;String&gt; providers; public Parser() { mLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); listener = new MyLocationListener(); listener.onProviderEnabled(LocationManager.GPS_PROVIDER); mLocationManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, MINIMUM_TIME_BETWEEN_UPDATES, MINIMUM_DISTANCE_CHANGE_FOR_UPDATES, listener); providers = mLocationManager.getProviders(true); timer = new Timer(); } public boolean parse(byte[] data) { gpsUpdater(); ... } private void gpsUpdater() { timer.scheduleAtFixedRate(new TimerTask() { Location l = null; @Override public void run() { for(String s: providers) { l = mLocationManager.getLastKnownLocation(s); if(l != null) { gps = true; latitude = l.getLatitude(); longitude = l.getLongitude(); } } } }, 0, MINIMUM_TIME_BETWEEN_UPDATES); } public class MyLocationListener implements LocationListener { @Override public void onLocationChanged(Location arg0) { //TODO Auto-generated method stub } @Override public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } @Override public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } @Override public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } } </code></pre> <p>and here is the error that i got:</p> <blockquote> <p>04-06 15:06:43.015: E/AndroidRuntime(844): FATAL EXCEPTION: Timer-0 04-06 15:06:43.015: E/AndroidRuntime(844): java.lang.SecurityException: Binder invocation to an incorrect interface 04-06 15:06:43.015: E/AndroidRuntime(844): at android.os.Parcel.readException(Parcel.java:1322) 04-06 15:06:43.015: E/AndroidRuntime(844): at android.os.Parcel.readException(Parcel.java:1276) 04-06 15:06:43.015: E/AndroidRuntime(844): at android.location.ILocationManager$Stub$Proxy.getLastKnownLocation(ILocationManager.java:896) 04-06 15:06:43.015: E/AndroidRuntime(844): at android.location.LocationManager.getLastKnownLocation(LocationManager.java:1020) 04-06 15:06:43.015: E/AndroidRuntime(844): at pt.ua.droidshark.handler.Parser$1.run(Parser.java:446) 04-06 15:06:43.015: E/AndroidRuntime(844): at java.util.Timer$TimerImpl.run(Timer.java:284)</p> </blockquote> <p>Could it be, that the location manager uses a kind of aidl to provide my app with the location and the phone can't handle such amount of information when all the communication is made using AIDL ? I can't understand why it works fine when I use intents and got this error always when i use AIDL.</p> <p>PS: Since someone suggested that the cause could be that the timer isn't in a service or activity class, I created a service in which i execute the code and i got the same situation. Works fine when all communication is made using intents and got the error when using AIDL.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload