Check gps status

I would like to show on my frontpage if the gps is not turned on. I want the same with my internet connechtion. It would be nice if it is updating regularly so users can see if the app get the requered informations. I have benne trying different ways but they do not seem to work. Do you have a better way.


  1. why a red cross is displayed in top of the initialize block? click on it to show us
  2. a search in google or community can help you, did you check Taifun's extensions? many extensions are available, check here
  1. The red cross is not important. I use the error system to find my blocks and it is easielly correchted.
  2. I have tried myself and searched when writing this question there was no advise. I am not looking in the extensions if there is an easielly accessible solution in the appinventor blocks.

no, there isn't any easily accessible in App Inventor blocks with requested feature. why you don't want to use an extension? have you ever tried them? its very easy to use them!

:question:

This is not true Arman. See the topic * Check Internet Connection In App Inventor at Imagnity for availability of Internet for a Blocks solution.

There are two ways for finding if the GPS turned on. One is to check for device settings using the ActivitySensor Gps enabled / disabled, but does it work? - #4 by SteveJG to determine if the device allows Location;

the other way is to check if LocationSensor1.Enabled is true to see if the LocationSensor is enabled or not..

3 posts were merged into an existing topic: Gps enabled / disabled, but does it work?

Hey Steve

I need a way to see if it works? And show it in by changing backhround colour in a labet. Is see the first of your options being a shortcut to the phone page were the snsor status is shown. The other one is more difficullt to understand. Is it the same as i have shown in my block or will the block has lattitude not inform the application.

Try coding some Blocks and see what happens,

Your block will not work to determine if the LocationSensor is active or not; HasLongitudeLatitude is used to determine if the device you are using has a gps or not (some tablets do not have gps hardware).
Location1.Enabled indicates whether the Location sensor is running or not.

The code using the ActivityStarter brings up the Android Setting screen to show whether your phone has Location services turned on or not It is not possible to change the setting using AI code Blocks this will tell the user whether the option is or is not turned on.

. Similar code used to work to change the setting program using code. Google now requires the device owner manually turn Location on for the gps to work; at least using AI Blocks. The code will show whether Location is on or off and offer a switch to change the state.

Regarding Internet, the code at Imagnity shows how to see if a Web site is available, the assumption if your device is connected by WIFI or data, the page will be available.

BackgroundColor Specifies the label’s background color as an alpha-red-green-blue integer.

Make a test Project and see if the recommendations will work for your purposes. The ActivityStarter doesn't turn on Location.. it merely allows the user to check status and turn Location on or off. This is the best that can be done using AI Blocks.
image

My wifi extension offers a method IsGpsEnabled

Taifun

Thank you very much.

You could try this example which show some of what you can do in Blocks.

ASLocationSettings.aia (3.8 KB)

How do you know the error numbers? here 1101?
And the Response codes? here 200 and 400?
I have tried to use the connection tjek you have shown, but the the tjeck woud be better on firebase the the google homepage. Is there a way to use the error block in firebase to make a connection tjek of the firebase connection.

I have also tried with procedure "location settings" where gps provider different from gps fires the blocks, but this fires allways also when the gps is enabled and works fine. Is the gps different in europe?
When is put the content of gps provider block in a label it says fused. I have tried changing gps with fused and this works, but will i keep working when location changes to other provider?

by searching error 1101 etc.

Error 1101: Unable To get a response with the specified URL

I don't use Firebase and don't know. This might help https://firebase.google.com/docs/analytics/errors

No. The same satellites used in Europe are used throughout the world :wink: . But different governments provide different satellite 'constellations' and can restrict use. (What's The Differences Between the 5 GNSS Constellations?) ...this gets too complicated to explain in a few words. Simply the MIT LocationSensor normally uses only GPS satellites in its satellite fixes.

fused is part of Google Play services Fused Location Provider API  |  Google for Developers that Google started using with Android 10 . It automatically selects gps, cell tower or WIFI etc.

Yes, but it won't change if you LockProvider after you set it to gps

I have tried to make a timer to regularly (5 sek interval)check the network and the the gps. It is difficult to tjek the network connechtion without building the app. Does this look right.




Try running it in Companion and tell us what happens. It might make the checks and report results just fine. A very quick look at the code, which I cannot obviously run seems ok. Five seconds in the TImer seems ok.

I can only test the gps as the companion needs the internet connechtion. The code is ok but it takes a long time to register a provider. I mean it takes like a minut after the connechtion is turned on.

?? takes a long time to register a provider.?? how are you doing this? Are you setting Provider to gps and then locking the Provider? I'm not sure when your device should expect to change from fused to gps . I think you don't want to compare ProviderName but perhaps you do? Since Android 10 and use of 'fused' the gps hardware has a mind of its own. What you are test for is not the presence of satellite signals. You can test for LocationSensor.Enabled (true or false).

Are you testing from your desk. Go for a drive; use Data instead of WIFI. Provider might switch faster then. A guess.

Its complicated. I know.
I turn on and off the gps localication on my android samsung phone.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.