[SOLVED} - GPS not triggering onLocationChanged

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

[SOLVED} - GPS not triggering onLocationChanged

Postby dapaintballer331 » Sun Dec 20, 2009 4:48 am

If somebody can get this to work for me, using an emulator on the 1.5 sdk, I will send them $25 via paypal if you need it. I am using the android 1.5 emulator. I rarely ask to give $, but I've been trying to fix this bug since July.

Problem: I see the satilite icon on the top of the phone, but when I send the device multiple coordinates, is never runs the onLocationChange method.

Assumptions: Ignore the "WakefulIntentService". Its just a modification of the service class, by Mark Murphy, that keeps the service running.

Question: Why isn't the emulator / my phone triggering onLocationChange, but displaying an icon signifying GPS is active when onHandleIntent is called? (And until stopUpdates is called). And, what can I do to fix this?



Code (FmiLocationManager.java):
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. package org.myProj;
  3.  
  4.  
  5.  
  6. import android.content.Context;
  7.  
  8. import android.content.Intent;
  9.  
  10. import android.location.LocationManager;
  11.  
  12. import android.location.Location;
  13.  
  14. import android.location.LocationListener;
  15.  
  16. import android.os.Bundle;
  17.  
  18. import android.os.IBinder;
  19.  
  20. import android.util.Log;
  21.  
  22. import android.location.Criteria;
  23.  
  24.  
  25.  
  26. public class FmiLocationManager extends WakefulIntentService implements LocationListener
  27.  
  28. {
  29.  
  30.         private LocationManager locationMan;
  31.  
  32.         private LocationListener locationLis;
  33.  
  34.        
  35.  
  36.        
  37.  
  38.         public FmiLocationManager()
  39.  
  40.         {
  41.  
  42.                 super("FmiLocationManager");
  43.  
  44.         }
  45.  
  46.        
  47.  
  48.         @Override
  49.  
  50.         protected void onHandleIntent(Intent intent) {
  51.  
  52.                 super.onHandleIntent(intent);
  53.  
  54.        
  55.  
  56.                 locationMan = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
  57.  
  58.                 String provider = "gps"; //(Available on the emulator, I tested it)
  59.  
  60.                 locationMan.requestLocationUpdates(
  61.  
  62.                             provider,
  63.  
  64.                             13000,
  65.  
  66.                             3,
  67.  
  68.                             this);
  69.  
  70.                 }
  71.  
  72.                
  73.  
  74.         }
  75.  
  76.                
  77.  
  78.        
  79.  
  80.        
  81.  
  82.         public void onStop()
  83.  
  84.         {
  85.  
  86.                 stopUpdates();
  87.  
  88.         }
  89.  
  90.        
  91.  
  92.         public void stopUpdates()
  93.  
  94.         {
  95.  
  96.                 if(locationLis != null)
  97.  
  98.                         locationMan.removeUpdates(locationLis);
  99.  
  100.         }
  101.  
  102.        
  103.  
  104.  
  105.  
  106.         @Override
  107.  
  108.         public IBinder onBind(Intent intent) {
  109.  
  110.                 return null;
  111.  
  112.         }
  113.  
  114.        
  115.  
  116.  
  117.  
  118.         public void onLocationChanged(Location loc) {
  119.  
  120.         Log.e("fmi","fmi new location received");
  121.  
  122.         //NEVER gets sent.
  123.  
  124.  
  125.  
  126.            }
  127.  
  128.  
  129.  
  130.          public void onProviderDisabled(String provider) {
  131.  
  132.          }
  133.  
  134.  
  135.  
  136.         public void onProviderEnabled(String provider) {
  137.  
  138.             }
  139.  
  140.    
  141.  
  142.     public void onStatusChanged(String provider, int status,
  143.  
  144.              Bundle extras) {
  145.  
  146.          }
  147.  
  148. }
Parsed in 0.037 seconds, using GeSHi 1.0.8.4





Manifest:
I won't post the entire thing, but here is the important information:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. android:versionName="1.0"
  2.  
  3. android:versionCode="1"
  4.  
  5.  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
  6.  
  7.         <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"></uses-permission>
  8.  
  9.         <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
  10.  
  11.         <uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
  12.  
  13. <service android:name=".FmiLocationManager" />
  14.  
  15.  
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


------------------------------------------------------------------------
Last edited by dapaintballer331 on Tue Dec 22, 2009 7:36 pm, edited 2 times in total.
dapaintballer331
Junior Developer
Junior Developer
 
Posts: 11
Joined: Wed Jul 01, 2009 2:03 am

Top

Postby Droid123 » Sun Dec 20, 2009 6:01 pm

why do you have two .RequestLocationUpdates?

I'm gonna test the location changed event in my application, it works on my HTC Hero, I'll test it on the emulator. Your code does look alright thought
Droid123
Experienced Developer
Experienced Developer
 
Posts: 77
Joined: Sat Nov 21, 2009 1:21 pm

Postby dapaintballer331 » Sun Dec 20, 2009 7:48 pm

Oh, I'll delete the first, it was there when i was debugging.
dapaintballer331
Junior Developer
Junior Developer
 
Posts: 11
Joined: Wed Jul 01, 2009 2:03 am

Postby Droid123 » Mon Dec 21, 2009 12:25 am

Well I tried my code on the emulator and on my HTC Hero.

on the Hero I get frequent updates of the GPS fix, and it calls my onLocationChanged method.

on the emulator I only managed to fire the onLocationChanged method once, even though I kept changing the coordinates in DDMS.... I don't know why this isn't working but at you know that there doesn't have to be an error in your code. In fact, your code is nearly the same as mine so it should work fine.

EDIT: Did you change your code? I didn't notice the onHandleIntent and wakefulintentservice before...
I'm assuming those work correctly... at least the handle to the location manager is correct, just make sure the code to create the handle gets called at least once
Droid123
Experienced Developer
Experienced Developer
 
Posts: 77
Joined: Sat Nov 21, 2009 1:21 pm

Postby dapaintballer331 » Mon Dec 21, 2009 7:48 am

Why woudln't the call to get the handle have been called once?
Yea the wakefulintent and onHandleIntent were always there, i only removed the duplicate call to requestLocationUpdates

I'm gonna keep tyring things... not sure what the issue is
dapaintballer331
Junior Developer
Junior Developer
 
Posts: 11
Joined: Wed Jul 01, 2009 2:03 am

Postby dapaintballer331 » Mon Dec 21, 2009 8:27 am

Seems I'm having trouble keeping my service running.
12-21 02:24:49.060: WARN/MessageQueue(267): java.lang.RuntimeException: Handler{43782188} sending message to a Handler on a dead thread
12-21 02:24:49.060: WARN/MessageQueue(267): at android.os.MessageQueue.enqueueMessage(MessageQueue.java:181)
12-21 02:24:49.060: WARN/MessageQueue(267): at android.os.Handler.sendMessageAtTime(Handler.java:457)
12-21 02:24:49.060: WARN/MessageQueue(267): at android.os.Handler.sendMessageDelayed(Handler.java:430)
12-21 02:24:49.060: WARN/MessageQueue(267): at android.os.Handler.sendMessage(Handler.java:367)
12-21 02:24:49.060: WARN/MessageQueue(267): at android.location.LocationManager$ListenerTransport.onLocationChanged(LocationManager.java:147)
12-21 02:24:49.060: WARN/MessageQueue(267): at android.location.ILocationListener$Stub.onTransact(ILocationListener.java:65)
12-21 02:24:49.060: WARN/MessageQueue(267): at android.os.Binder.execTransact(Binder.java:287)
12-21 02:24:49.060: WARN/MessageQueue(267): at dalvik.system.NativeStart.run(Native Method)
12-21 02:24:49.070: WARN/MessageQueue(267): Handler{437aca88} sending message to a Handler on a dead thread

Using a service or wakefulintent service, I still get this. I had aquireStaticWakeLock called before my WakefulIntentService was started...


Any tips on keeping my service "active"?
dapaintballer331
Junior Developer
Junior Developer
 
Posts: 11
Joined: Wed Jul 01, 2009 2:03 am

Top

Postby dapaintballer331 » Tue Dec 22, 2009 7:37 pm

Thanks a lot for your support everyone!
I winded up doing many things, most of which were required for this to
work.
1. Used the WakefulIntentService, and at the bottom of onHandleIntent,
manually called onStop
2. Right away I created a wakelock
3. BEFORE the first requestLocationUpdates(yadaa yadda yadda, this) I
called releaseUpdates(this).
4. Removed the accidental duplicate requestLocationUpdates
5. Added a sleep timer to onHandleIntent, and had it call onStop
afterwards (releases the wakelock and locationupdates)
The main issue was keeping the service awake, second issue was all the
stupid bugs in the 1.5 OS.
dapaintballer331
Junior Developer
Junior Developer
 
Posts: 11
Joined: Wed Jul 01, 2009 2:03 am

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 4 guests