GPS location from service

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

GPS location from service

Postby yaourt » Tue Aug 03, 2010 8:12 am

Hi,

i'm developing a background service which tries to get one gps location update. Somehow i can't get the service to work and i think i might not understand how the gps request works properly. When i request the location update the code never returns from there.
Here is my code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class PositionService extends Service implements ServiceConnection {
  2. private final static String TAG = "PositionService";
  3.        
  4.         private Postman postman;
  5.         private DatabaseHelper db;
  6.         private ICollectorService service;
  7.         private SharedPreferences pref;
  8.         private LocationManager locManager;
  9.        
  10.         @Override
  11.         public void onCreate() {
  12.                 postman = new Postman();
  13.                 db = new DatabaseHelper(this);
  14.                 pref = PreferenceManager.getDefaultSharedPreferences(this);
  15.                 locManager = (LocationManager) getSystemService(LOCATION_SERVICE);
  16.                
  17.                 ...
  18.         }
  19.        
  20.         private IScopeService.Stub binder = new IScopeService.Stub() {
  21.  
  22.                
  23.                 public boolean fetchData() throws RemoteException {
  24.                         Log.d(TAG, "determing position");
  25.                         MyLocationListener locListener = new MyLocationListener();
  26.                         locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locListener);
  27.                         Log.d(TAG, "i never get here");
  28.                         return true;
  29.                 }
  30.                
  31.         };
  32.        
  33.        
  34.         public class MyLocationListener implements LocationListener {
  35.  
  36.                
  37.                 public void onLocationChanged(Location location) {
  38.                         Log.d(TAG, "location changed");
  39.                 }
  40.  
  41.        
  42.                 public void onProviderDisabled(String provider) {
  43.                         Log.d(TAG, "disabled");
  44.                 }
  45.  
  46.                
  47.                 public void onProviderEnabled(String provider) {
  48.                         Log.d(TAG, "enabled");
  49.                 }
  50.                
  51.                 public void onStatusChanged(String provider, int status, Bundle extras) {
  52.                         String showStatus = "sdgsg";
  53.             if (status == LocationProvider.AVAILABLE)
  54.                     showStatus = "Available";
  55.             if (status == LocationProvider.TEMPORARILY_UNAVAILABLE)
  56.                     showStatus = "Temporarily Unavailable";
  57.             if (status == LocationProvider.OUT_OF_SERVICE)
  58.                     showStatus = "Out of Service";
  59.             Log.d(TAG, showStatus);
  60.                 }
  61.                
  62.         }
  63. ............
  64. }
  65.  
Parsed in 0.038 seconds, using GeSHi 1.0.8.4
yaourt
Freshman
Freshman
 
Posts: 7
Joined: Thu Dec 17, 2009 12:34 pm

Top

Re: GPS location from service

Postby blundell » Wed Aug 04, 2010 9:00 am

Surely Logcat gives an error?

I would say your not allowed GPS requests to be passed to your app every 0 seconds with 0 range, this line:
locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locListener);
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: GPS location from service

Postby yaourt » Wed Aug 04, 2010 9:15 am

Logcat gives no error. I never reach the line after the request:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Log.d(TAG, "determing position");
  2. MyLocationListener locListener = new MyLocationListener();
  3. locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locListener);
  4. Log.d(TAG, "i never get here");
  5.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

I played a little with the numbers in the request but that changes nothing. I have the access_fine_location permission in the manifest file and i don't know what to do. Am i missing something?
Is it right that there has to come a gps symbol if it works like in the google maps app?
yaourt
Freshman
Freshman
 
Posts: 7
Joined: Thu Dec 17, 2009 12:34 pm

Re: GPS location from service

Postby blundell » Wed Aug 04, 2010 10:00 am

So what does your log show? Does is say "determining position"?
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: GPS location from service

Postby yaourt » Wed Aug 04, 2010 10:01 am

Yes exactly, it says "determing position" but nothing more.
yaourt
Freshman
Freshman
 
Posts: 7
Joined: Thu Dec 17, 2009 12:34 pm

Re: GPS location from service

Postby blundell » Wed Aug 04, 2010 10:12 am

C'mon this is like blood from a stone, what ELSE does your Logcat say? Help me help you
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Top

Re: GPS location from service

Postby yaourt » Wed Aug 04, 2010 10:23 am

I'm sorry but the rest of the log is about other services. Here it is
Code: Select all
08-04 11:16:53.787: DEBUG/dalvikvm(5923): GC freed 5561 objects / 354744 bytes in 59ms
08-04 11:16:55.427: DEBUG/BluetoothService2(5923): starting scan
08-04 11:16:55.427: DEBUG/PositionService(5923): determing position
08-04 11:16:55.447: ERROR/BluetoothEventLoop.cpp(88): pollData[0] is revented, check next one
08-04 11:16:55.447: ERROR/BluetoothService.cpp(88): stopDiscoveryNative: D-Bus error in StopDiscovery: org.bluez.Error.Failed (Invalid discovery session)
08-04 11:16:55.467: INFO/DTUN_CLNT(641):     Client calling DTUN_METHOD_DM_START_DISCOVERY (id 2)
08-04 11:16:55.467: INFO/(626): DTUN_ReceiveCtrlMsg: [DTUN] Received message [BTLIF_DTUN_METHOD_CALL] 4354
08-04 11:16:55.467: INFO/(626): handle_method_call: handle_method_call :: received DTUN_METHOD_DM_START_DISCOVERY (id 2), len 0
08-04 11:16:55.467: DEBUG/BTL_CFG(626): +btl_cfg_getBDAFilterCond getting property service.brcm.bt.INQ_FILTER_BDA
08-04 11:16:55.467: ERROR/BTL_CFG(626): WARNING : property_get failed (0)
08-04 11:16:55.467: DEBUG/BTL_CFG(626): -btl_cfg_getBDAFilterCond bdaddr=, nRet=0
08-04 11:16:55.467: WARN/BTLD(626): bta_dm_check_av:0
08-04 11:16:55.467: INFO/BTL-IFS(626): send_ctrl_msg: [BTL_IFS CTRL] send BTLIF_DTUN_SIGNAL_EVT (CTRL) 4 pbytes (hdl 14)
08-04 11:16:55.467: INFO//system/bin/btld(625):         btapp_dm_DiscoverDevices()
08-04 11:16:55.467: INFO//system/bin/btld(625): ##### USerial_Ioctl: BT_Wake, 0x8003 ####
08-04 11:16:55.477: INFO/ADAPTER(641): Discovery session 0xc7b8 with :1.0 activated
08-04 11:16:55.477: DEBUG/ADAPTER(641): session_ref(0xc7b8): ref=1
08-04 11:16:55.477: DEBUG/DTUN_HCID_BZ4(641):         dtun_dm_sig_discovery_started()
08-04 11:16:55.477: ERROR/BluetoothEventLoop.cpp(88): pollData[0] is revented, check next one
08-04 11:16:55.477: ERROR/BluetoothEventLoop.cpp(88): pollData[0] is revented, check next one
08-04 11:16:55.477: ERROR/BluetoothEventLoop.cpp(88): event_filter: Received signal org.bluez.Adapter:PropertyChanged from /org/bluez/641/hci0
08-04 11:16:55.477: VERBOSE/BluetoothEventRedirector(192): Received android.bluetooth.adapter.action.DISCOVERY_STARTED
08-04 11:16:56.077: INFO//system/bin/btld(625): ##### USerial_Ioctl: BT_Sleep, 0x8004 ####
08-04 11:16:56.427: INFO/wpa_supplicant(131): CTRL-EVENT-SCAN-RESULTS  Ready
08-04 11:16:56.427: INFO/wpa_supplicant(131): - wpa_supplicant_event_scan_results RETURN (ap_scan = 2)-
08-04 11:16:56.447: DEBUG/WifiService(5923): wifi scan 1 done
08-04 11:16:59.030: INFO/wpa_supplicant(131): CTRL-EVENT-SCAN-RESULTS  Ready
08-04 11:16:59.030: INFO/wpa_supplicant(131): - wpa_supplicant_event_scan_results RETURN (ap_scan = 2)-
08-04 11:16:59.037: DEBUG/WifiService(5923): wifi scan 2 done
08-04 11:16:59.887: DEBUG/dalvikvm(5923): GC freed 5856 objects / 521936 bytes in 52ms
08-04 11:17:03.787: INFO/wpa_supplicant(131): CTRL-EVENT-SCAN-RESULTS  Ready
08-04 11:17:03.787: INFO/wpa_supplicant(131): - wpa_supplicant_event_scan_results RETURN (ap_scan = 2)-
08-04 11:17:03.807: DEBUG/WifiService(5923): wifi scan 3 done
08-04 11:17:07.937: INFO/wpa_supplicant(131): CTRL-EVENT-SCAN-RESULTS  Ready
08-04 11:17:07.937: INFO/wpa_supplicant(131): - wpa_supplicant_event_scan_results RETURN (ap_scan = 2)-
08-04 11:17:07.937: DEBUG/WifiService(5923): wifi scan 4 done
08-04 11:17:08.297: INFO/BTL-IFS(626): send_ctrl_msg: [BTL_IFS CTRL] send BTLIF_DTUN_SIGNAL_EVT (CTRL) 4 pbytes (hdl 14)
08-04 11:17:08.297: DEBUG/DTUN_HCID_BZ4(641):         dtun_dm_sig_discovery_complete()
08-04 11:17:08.297: ERROR/BluetoothEventLoop.cpp(88): pollData[0] is revented, check next one
08-04 11:17:08.297: ERROR/BluetoothEventLoop.cpp(88): event_filter: Received signal org.bluez.Adapter:PropertyChanged from /org/bluez/641/hci0
08-04 11:17:08.297: DEBUG/ADAPTER(641): session_unref(0xc7b8): ref=0
08-04 11:17:08.297: DEBUG/ADAPTER(641): Discovery session 0xc7b8 with :1.0 deactivated
08-04 11:17:08.297: DEBUG/ADAPTER(641): Stopping discovery
08-04 11:17:08.297: INFO/DTUN_CLNT(641):     Client calling DTUN_METHOD_DM_CANCEL_DISCOVERY (id 3)
08-04 11:17:08.297: INFO/(626): DTUN_ReceiveCtrlMsg: [DTUN] Received message [BTLIF_DTUN_METHOD_CALL] 4354
08-04 11:17:08.297: INFO/(626): handle_method_call: handle_method_call :: received DTUN_METHOD_DM_CANCEL_DISCOVERY (id 3), len 0
08-04 11:17:08.297: INFO//system/bin/btld(625):         btapp_dm_CancelDiscovery()
08-04 11:17:08.307: INFO/ADAPTER(641): Stopping discovery
08-04 11:17:08.307: VERBOSE/BluetoothEventRedirector(192): Received android.bluetooth.adapter.action.DISCOVERY_FINISHED
08-04 11:17:09.537: DEBUG/dalvikvm(5923): GC freed 7754 objects / 710672 bytes in 45ms
08-04 11:17:09.547: INFO/BluetoothService2(5923): update send to broker
08-04 11:17:09.547: DEBUG/BluetoothService2(5923): no devices found
08-04 11:17:09.567: INFO/TasksInfoService(5923): update send to broker
08-04 11:17:09.757: INFO/DevSettingsService(5923): update send to broker
08-04 11:17:09.918: INFO/wpa_supplicant(131): CTRL-EVENT-SCAN-RESULTS  Ready
08-04 11:17:09.918: INFO/wpa_supplicant(131): - wpa_supplicant_event_scan_results RETURN (ap_scan = 2)-
08-04 11:17:09.937: DEBUG/WifiService(5923): wifi scan 5 done
08-04 11:17:10.157: INFO/WifiService(5923): update send to broker
08-04 11:17:12.557: INFO/MotionService(5923): update send to broker
08-04 11:17:12.587: INFO/DevStatusService(5923): update send to broker
08-04 11:17:17.067: INFO/CellService(5923): update send to broker
08-04 11:17:18.597: DEBUG/dalvikvm(5923): GC freed 8000 objects / 681368 bytes in 64ms
08-04 11:17:19.827: DEBUG/dalvikvm(323): GC freed 428 objects / 25992 bytes in 76ms
08-04 11:17:28.837: DEBUG/dalvikvm(489): GC freed 16 objects / 712 bytes in 75ms
08-04 11:17:37.837: DEBUG/dalvikvm(780): GC freed 276 objects / 60240 bytes in 74ms
08-04 11:17:46.297: DEBUG/HtcLockScreen(88): onRefreshBatteryInfo: 96
08-04 11:17:46.297: INFO/HtcLockScreen(88): updateStatusViewByPriority, mIsSimCheckView = false, mIsBatteryInfo = false, mIsMusicPlaying = false, mIsAirPlaneMode = false
08-04 11:17:46.297: DEBUG/WifiService(88): ACTION_BATTERY_CHANGED pluggedType: 2
08-04 11:17:46.317: INFO/global(88): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
08-04 11:17:46.317: INFO/global(88): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
08-04 11:17:46.317: DEBUG/BatteryService(88): isUsbConnected() = true
08-04 11:17:46.317: DEBUG/BatteryService(88): mPlugType = 2
08-04 11:17:46.327: DEBUG/UsbConnectedReceiver(323): action = psclient.intent.action.usb_status
08-04 11:17:46.327: DEBUG/UsbConnectedReceiver(323): ACTION_BATTERY_CHANGED
08-04 11:17:46.327: DEBUG/UsbConnectedReceiver(323): usbCurrentType = 2
08-04 11:17:46.327: DEBUG/UsbConnectedReceiver(323): Current type is same as previous, return!
08-04 11:17:51.397: DEBUG/dalvikvm(478): GC freed 435 objects / 35624 bytes in 75ms
08-04 11:17:56.397: DEBUG/dalvikvm(701): GC freed 45 objects / 2280 bytes in 69ms
08-04 11:18:05.157: DEBUG/dalvikvm(367): GC freed 192 objects / 9728 bytes in 71ms
08-04 11:18:10.167: DEBUG/dalvikvm(387): GC freed 5595 objects / 309784 bytes in 81ms
08-04 11:18:12.558: DEBUG/PositionService(5923): determing position
08-04 11:18:22.837: DEBUG/dalvikvm(681): GC freed 895 objects / 63016 bytes in 74ms
08-04 11:18:25.257: DEBUG/dalvikvm(5923): GC freed 9443 objects / 485912 bytes in 39ms
08-04 11:18:27.877: DEBUG/dalvikvm(174): GC freed 5402 objects / 296136 bytes in 112ms
08-04 11:19:11.137: INFO/wpa_supplicant(131): CTRL-EVENT-SCAN-RESULTS  Ready
08-04 11:19:11.137: INFO/wpa_supplicant(131): - wpa_supplicant_event_scan_results RETURN (ap_scan = 2)-
08-04 11:19:11.147: DEBUG/WifiService(5923): wifi scan 1 done
08-04 11:19:13.139: INFO/wpa_supplicant(131): CTRL-EVENT-SCAN-RESULTS  Ready
08-04 11:19:13.139: INFO/wpa_supplicant(131): - wpa_supplicant_event_scan_results RETURN (ap_scan = 2)-
08-04 11:19:13.147: DEBUG/WifiService(5923): wifi scan 2 done
08-04 11:19:15.137: INFO/wpa_supplicant(131): CTRL-EVENT-SCAN-RESULTS  Ready
08-04 11:19:15.137: INFO/wpa_supplicant(131): - wpa_supplicant_event_scan_results RETURN (ap_scan = 2)-
08-04 11:19:15.147: DEBUG/WifiService(5923): wifi scan 3 done
08-04 11:19:17.130: INFO/wpa_supplicant(131): CTRL-EVENT-SCAN-RESULTS  Ready
08-04 11:19:17.130: INFO/wpa_supplicant(131): - wpa_supplicant_event_scan_results RETURN (ap_scan = 2)-
08-04 11:19:17.147: DEBUG/WifiService(5923): wifi scan 4 done

There is no error message except during the bluetooth scan but that works fine. So the only entry for the PositionService is "determing position" (line 3 and somewhere at the end).
yaourt
Freshman
Freshman
 
Posts: 7
Joined: Thu Dec 17, 2009 12:34 pm

Re: GPS location from service

Postby blundell » Wed Aug 04, 2010 10:38 am

Try moving
locManager = (LocationManager) getSystemService(LOCATION_SERVICE);

into onStart and not onCreate.

I have no clue tbh, I would recommend extracting the GPS functionality and getting it to work in a stub service project. If that doesn't work try to implement it in an activity. If that doesn't work, hell! jump!
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 3 guests