0

I'm coding around with the app inventor2 project "No Text While Driving". I need to add some more functionality, as the app to determine if the smartphone is on the move, e.g. in a rolling car and thus lock the screen or prevent from being able to answer incoming sms.

In theory, I know I should have a block to check current location to previous location of the smartphone in the amount of time. Or is it possible to check movement only by accelerometer?

I have tried the following blocks without much success: enter image description here

Can someone kind enough direct me to the wright use of blocks through an example? Thank you all in advance for your answers.

[Update1]

I have tried to follow Taifun's advice by adding the LocationSensor1 reading to a global variable and compare it with the CurrentAddress. The following code blocks should do the trick, but it didn't. Is it possible to check movement with accelerometer reading instead, and how?

Here is the updated blocks: enter image description here

CodeBugging
  • 321
  • 12
  • 28
  • What about passengers in the car? "No texting while riding"? – Chet Dec 11 '15 at 18:21
  • in an App Inventor app, you neither can lock the screen nor prevent the user from answering incoming sms... – Taifun Dec 11 '15 at 20:27
  • to set the current address to a variable and immediately after that compare it again with the current address always will give you the result, that both are identical... Therefore after having received a valid address the first time, then set the global variable and then start testing, if you are moving... To get the first valid address might take a few seconds... – Taifun Dec 13 '15 at 13:49

1 Answers1

0

You will need to store the result, wait a few seconds, check the sensor data again and compare to stored value. Then replace the stored value with the new one. Repeat.

Chet
  • 3,461
  • 1
  • 19
  • 24
  • Hi @Chet. Is it possible to post a block of code as an example. I'm not very familiar yet with TinyDB component usage. – CodeBugging Dec 11 '15 at 20:12
  • I have never used it, just trying to help you formulate the solution. – Chet Dec 11 '15 at 20:19
  • you do not need `TinyDB`, just store the result in a global variable... it probably would help to do some tutorials first to learn some basics... – Taifun Dec 11 '15 at 20:28
  • Hi @Taifun. Did some basic tuts, already. So if I store the LocationSensor1 data in a global variable, then I should have another LocationSensor2 or another variable to compare with? Can you elaborate a little on this, or direct me to a similar function tutorial or to an example of usage? – CodeBugging Dec 11 '15 at 21:10
  • You store the LocationSensor1.CurrentAddress in a global variable and next time you compare the current value of LocationSensor.CurrentAddress with the global variable. If it's different, then you moved... It does not look like you understand the concept of a global variable, do you? Doing some more tutorials probably would help... – Taifun Dec 11 '15 at 22:18
  • Hi @Taifun. Have tried to follow your advice with the global variable. Don't know what I did wrong, maybe is the GPS weak, but I get not the notifier to fire upon movement. Can the movement check be done using accelerometer instead and how? Have read the tuts, but find nothing but "the free fall" checking. Please advice. – CodeBugging Dec 13 '15 at 13:19
  • Do you even get an initial location? – Chet Dec 13 '15 at 13:46
  • Hi @Chet. Nop I didn't. Guess GPS is not very reliable (slow) on the device. Thus I'm asking If it is possible to get the movement checked by using Accelerometer sensor. How can this be done? Do I have to check X,Y,Z, value changes simultaneously? – CodeBugging Dec 13 '15 at 19:37
  • Accelerometer will not be useful to see if user is driving. Especially because once car gets to cruise speed it will no longer be accelerating. – Chet Dec 13 '15 at 19:49
  • So @Chet, the only way to determine if the mobile is in a cruising car, is through GPS and location sensory? To bad you haven't used it before, so you can post some sample blocks coding. – CodeBugging Dec 13 '15 at 20:06
  • Yes, that is the case. Sorry I can't post some blocks. Since this.question is old you would have more luck opening a new question simply asking how to get GPS working in App Inventor 2. – Chet Dec 13 '15 at 20:14
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/97789/discussion-between-user3244633-and-chet). – CodeBugging Dec 13 '15 at 20:37