Checking GPS support

113 views
Skip to first unread message

cubiq1

unread,
Jun 9, 2014, 5:04:38 AM6/9/14
to codenameone...@googlegroups.com
Hello,

I need to enable/disable certain features in my app based on whether the host device has a GPS receiver.

What would be the quickest, most reliable way to check for this?

Many thanks

Shai Almog

unread,
Jun 9, 2014, 10:07:04 AM6/9/14
to codenameone...@googlegroups.com
Hi,
you mean GPS physically non-existent?
For that case LocationManager will be returned as null.

If you mean lack of service you will need to listen to the status and check if its an error status.

cubiq1

unread,
Jun 9, 2014, 11:49:56 AM6/9/14
to codenameone...@googlegroups.com
Thanks Shai, just what I was looking for.

Do you know why on J2ME (Nokia N8) and RIM (BB 9800 Torch) the following code doesn't show the InfiniteProgress spinner?

      final Dialog dlg = new InfiniteProgress().showInifiniteBlocking();
      dlg
.show();
           
     
Location position = LocationManager.getLocationManager().getCurrentLocationSync();

On both Android and Windows Phone the spinner shows just fine.

Thanks

Shai Almog

unread,
Jun 10, 2014, 1:39:54 AM6/10/14
to codenameone...@googlegroups.com
This should work.
Maybe its the dialog transition try dlg.setTransitionIn(CommonTransition.createEmpty()); before the show();

cubiq1

unread,
Jun 11, 2014, 10:46:33 AM6/11/14
to codenameone...@googlegroups.com
Hi, unfortunately adding the line below doesn't fix the issue.

I tried the following code and noticed the InfiniteProgress spinner gets 'frozen' (similar to calling Thread.sleep()).

    final Dialog dlg = new InfiniteProgress().showInifiniteBlocking();

    dlg
.setTransitionInAnimator(CommonTransitions.createEmpty());
    dlg
.show();

   
Dialog.show("Success", "GPS supported", "Okay", null);

   
Location position = LocationManager.getLocationManager().getCurrentLocationSync();

Is this because getLocationSync() runs on the EDT and is blocking the spinner animation?

Thanks

Shai Almog

unread,
Jun 11, 2014, 12:27:26 PM6/11/14
to codenameone...@googlegroups.com
Hi,
its invokeAndBlock() so it should be fine. There is a limit to invokeAndBlock() but if it works on other platforms its surprising.

cubiq1

unread,
Jun 12, 2014, 1:53:09 PM6/12/14
to codenameone...@googlegroups.com
Hi,

Is there anything I can do to fix this? Or is this 'freezing' behaviour a limitation on the J2ME and RIM platforms?

I only need to get location once in the app so using getCurrentLocationSync() seemed like the best option.

The spinner works fine on the simulator, and on actual Android and WP devices (I haven't tried iOS). It's just J2ME and RIM devices causing issues.

Thanks

Shai Almog

unread,
Jun 13, 2014, 1:39:28 AM6/13/14
to codenameone...@googlegroups.com
Hi,
I actually have no idea why this is happening to you. It shouldn't be OS specific and should work as expected regardless of the OS.
Its possible that the GPS call takes up all the CPU and creates a special case for those platforms in which case there is probably nothing we can do to improve it.

cubiq1

unread,
Jun 18, 2014, 9:40:25 AM6/18/14
to codenameone...@googlegroups.com
Hi,

Thanks, I'll have to make do.

When checking for GPS on both a Nokia Asha 111 and 201, I get told that GPS is supported (even though neither of the phones has a GPS receiver), and then a Bluetooth device search window pops up, obviously looking for a Bluetooth GPS receiver in the vicinity.

Is there any way to disable this?

Shai Almog

unread,
Jun 18, 2014, 10:14:24 AM6/18/14
to codenameone...@googlegroups.com
Hi,
we are just checking the existence of the JSR 179 API.
I'm sure there is a way to avoid that but we probably won't investigate that, maybe with native code.

cubiq1

unread,
Jun 30, 2014, 12:45:31 PM6/30/14
to codenameone...@googlegroups.com
Hi,

Say I want to get my current location just once, asynchronously, and then stop the listener from further getting my location.

What would be the best way to achieve this?

Many thanks

Shai Almog

unread,
Jul 1, 2014, 1:04:48 AM7/1/14
to codenameone...@googlegroups.com
Hi,
that's exactly what getCurrentLocationSync() does and you can invoke it from a separate thread.
Alternatively you can bind a listener and when you get a response set it to null.

cubiq1

unread,
Jul 1, 2014, 12:30:08 PM7/1/14
to codenameone...@googlegroups.com
Hi,

Unfortunately getCurrentLocationSync() locks up the UI on both J2ME and RIM platforms. Would invoking it from a separate thread fix the issue?

Thanks

Shai Almog

unread,
Jul 2, 2014, 1:27:30 AM7/2/14
to codenameone...@googlegroups.com
Hi,
probably.
Reply all
Reply to author
Forward
0 new messages