Page 1 of 1

api call not working on android

Posted: Sat Jan 04, 2020 1:27 am
by paulalsmith1000
Evening livecoders

Well I'm here again, its heading towards 1 in the morning and I'm stumped again. As ever any help would be very much appreciated:

I am making an api call to google distance matrix, it works fine on the desktop, but not on android. As far as I can tell nothing is returned??!!!!

The code is-

command check_distance_to_school_only
if the environment is "mobile" then
set the defaultFolder to specialFolderPath("external documents")
end if
put URL ("file:saved_currentlocation.txt") into tphone_location
put URL ("file:saved_school_location.txt") into tschool_location
put URL ("file:saved_school_geof_size.txt") into tgeof
put "https://maps.googleapis.com/maps/api/di ... n?origins=" & tphone_location & "&destinations=" & tschool_location & "&mode=walking&key=AIzaSyCF13NFbjMMz7zETlkSoMpuIdVjYr8a9Ew" into tlocation_request
put URL (tlocation_request) into tlocation_response --NOTE just put brackets in to check
put jsontoarray(tlocation_response) into tdistance_Array
put tdistance_Array["rows"]["1"]["elements"]["1"]["distance"]["value"] into tdistance_from_school
put tdistance_from_school into URL ("file:saved_current_distance_from_school.txt")
if tdistance_from_school <= tgeof then
put "in school" into URL ("file:saved_current_location_type.txt")
else
put "out of school" into URL ("file:saved_current_location_type.txt")
end if
end check_distance_to_school_only

Thanks again

Paul

Re: api call not working on android

Posted: Sat Jan 04, 2020 9:51 am
by jmburnod
Hi Paul,
Not sure that is the issue but as far i know specialFolderPath("external documents") doesn't exists.
You maybe mean specialFolderPath("documents")
Best regards
Jean-Marc

Re: api call not working on android

Posted: Sat Jan 04, 2020 10:27 am
by bogs
Heya J-M, it apparently exists now.
Dictionary wrote: On Android systems, note that the file system is case-sensitive.
<sic>
The following folderIdentifier values are supported:

"documents": The folder where application-specific data can be placed (typically valuable)
"cache": The folder where transient application-specific data can be placed (typically not valuable)
"temporary": Same as "cache"
"engine": The (virtual) folder containing the application's LiveCode engine and other resources that were copied into the application at build time
"resources": Same as "engine".
"external documents": The folder on the primary shared/external storage device where application-specific data can be placed
"external cache": The folder on the primary shared/external storage device where transient application-specific data can be placed
"external temporary": same as "external cache"

Note: If using any external folderIdentifier values, ensure you have the 'Write External Storage' permission checked in the application standalone settings
Sorry Paul, I have no contribution to your actual issue.

You said it works "fine on the desktop", are you talking about from within the IDE, run from an emulator, or run as an actual desktop standalone? Would also be helpful to know which vers. of Lc your running, although I suspect it is one of the more recent versions since, as Jean-Marc said, that special folder path wasn't around very long.

Re: api call not working on android

Posted: Sat Jan 04, 2020 10:46 am
by jmburnod
Thanks Bog, dictionary is my friend... until the end of the text (as far I know) :oops:
I suspect it is one of the more recent versions
I can see it in LC 8.1.9

Re: api call not working on android

Posted: Sat Jan 04, 2020 10:51 am
by bogs
Heh, I think we have all had it happen Jean-Marc. I know I've gotten it wrong even reading the dictionary entry, just because of the wording used and my interpretation of it, so don't feel all alone :wink:

Re: api call not working on android

Posted: Mon Jan 06, 2020 9:00 am
by jacque
I tend to avoid setting the defaultfolder, especially on mobile. You might try using the complete file path:

put specialfolderpath("external documents") & "/saved_current_distance_from_school.txt" into tPath
put tdistance_from_school into into url ("file:" & tPath)

If that doesn't work try adding a slash or two: "file://"