2017년 4월 2일 일요일

AI Companion and Build


Hi, some time ago with help from Abraham Getzler, I created an weather app that receive data from an arduino. A few days ago I encountered a problem with SMS receiving and/or displaying data. I mention that the problem occurs only with standalone app ( I mean the application built and installed on the device ). If I use AI Companion I don't encounter this problem ( everything works perfect ). The problem is that when I receive an SMS, data from it are not displayed in the application and  I have no idea why. I need to add anything in order to use the application without Companion ?

Here is the code from app if needed ( apologies for foreign language ).




--
is the app up and running while you are receiving the sms?
it might help to add an else part to the if statement to display a message in case something was sent from another phone number...

-- 
The app is running yes. I don't need to add an else part because I want to display on my app only the data received from a certain number. However any other SMS received from other numbers can be read using the phone default SMS app

-- 
you said
 The problem is that when I receive an SMS, data from it are not displayed in the application and  I have no idea why. 

so at least as test I would add an else to be able to exclude the phone number being the issue...

-- 
I encounter the same problem. When I use AI Companion, the data are displayed and when I use the instaled app the data are not displayed. 


Another phone number.


-- 
try an else as suggested
-- 
On builded app after any SMS I received it displays TEST ( declared number and others ). On Companion, if I receive a SMS from declared app it's display the data transmitted and if I receive a SMS from another number it's display TEST.

-- 
which means, you now know that the phone number is the issue...
what about dislaying the phone number as test, then build the app, test again and after that use that phone number in your logic?

-- 
So identifying the number is the problem.



If I remove the identification part, the received data is displayed properly on builded app. But I must implement a way to identify the number, to eliminate the problem of a SMS with false data sent from another number. And most importantly without that part after any received SMS I get this :












I tried to use the = block from Logic Blocks but same problem.

But I wonder, why it works in Companion and not as builded app ?
And the number must have the country code.

-- 
so what is the difference in the phone numbers?
is it probably the country code?
which phone number do you get after building the app compared to the companion app?

-- 
The country code is not the problem. The country code must be implemented only if I introduce the identification part to be able to display the data. But this work only in Companion.
The phone number also not the problem. No matter from what number I received SMS  it displays the number, but without the identification part. If I use identification for both numbers, the app display noting. Identification part work only in AI Companion.
The problem is here : 


And I can not figure how to solve it.

--
The phone number also not the problem

???
well, earlier you found out, that the phone number is the problem else your if statement would always work...
you still could not tell us the difference in the phone numbers...

which phone number do you get after building the app compared to the companion app?


-- 
Maybe this will explain better.

So I concluded that identification is the problem.
I do not know what other difference in the phone numbers you mean.

-- 
For debugging purposes, I propose collecting incoming numbers and messages in a list,
and displaying them in a monospace diagnostic label in JSON format, which wraps
text in quotes to help show blanks.

In Screen1's Designer attributes, check the attribute that turns on JSON format.

Add message_log label to screen, set to monospace font

Initialize a global variable message_log to an empty list.
When messages arrive, 
  insert at position 1 of message_log (create list(number,message))
  set diagnostic label.Text to message_log

Check numbers in the log label for unusual formatting differences.

-- 
I created the list and the numbers are correct.



-- 
I think it's because you store the phone number as text and trying to compare it using maths block. you should use logic block instead. maybe it helps

--
Hi Pavitra, I tried to use logic blocks but I encountered the same problem. I also tried to use for number,a constant from math block but it can not contain + and can not start with 0.
But still I do not understand why it works in companion.

-- 
note: the 2 compare blocks are identical, see also http://appinventor.mit.edu/explore/ai2/support/blocks/logic.html#=

Acts exactly the same as the = block found in Math

try the attached example project and let us know your results
a) in the companion app
b) after building the app 


if you send a text message from the defined phone number, in both cases you should get the result "message received from defined phone number"
if not, you might want to tell us more about the device and Android version you are using for your tests
did you also try another device?


-- 
On Companion I receive "message received from defined phone number".
After building the app  I receive "message received from +40799...

I use a Samsumg Galaxy S6 with Android 6.0.1. 
Also tried on a Vodafone Tab Prime 6 with Android 5.0.2 and LG l70 with Android 4.4.2. 
Same result for all devices.


-- 
The log shows the answer.

The logged incoming numbers have blanks between  groups of digits.
That breaks the comparison with your number, which does not have the internal blank.
Try running the incoming number through a replace blank with empty string block
before comparing it or looking it up in a list.



-- 



You mean like that ? At segment come that blank " " and replacement "". Still does not display data in builded app


-- 
You are scrubbing blanks from your text constant, which does not have blanks.
You are supposed to remove the blanks from number.

Be careful that you blank text block actually has a blank in it, as opposed to being empty.
AI2 has a nasty habit of eating blanks from text blocks, unless you go back and insert them.

Read what you wright.


-- 
It works ! But why in companion, the app works without the replacement block ? Anyway thank you ABG, Taifun and Pavitra.

--

! But why in companion, the app works without the replacement block 

An interesting question.

Show us the number log from a Companion run, so we can see how the formatting of number
changes in the Companion.

-- 
Maybe something happen during the building or Companion has a nasty habit of eating blanks from text blocks as you said.

AI Companion 







Built app



-- 
Here's an alternative guess and how to deal with it ...

Since the phone dialer components of most software ignore blanks, 
different manufacturers might "help" (quotes mine) users by
doing them the "favor" of adding spaces and maybe dashes or
parentheses to their phone numbers to "help" the user read them.

Such "helpful" behavior should be anticipated by any one trying to compare
phone numbers, by scrubbing all whitespace  (+ -()) from phone numbers before
comparing them.


--

댓글 없음:

댓글 쓰기