AppInventor: HOWTO: Test If Image Exists on Device (no extension required)

This one has been bugging me for a few days, and despite the wonderfulness of the File extension from Taifun, I have been searching for a way to test for the existence of an image file using just AI2 blocks and components.

Why do you need this? (for whatever reason you don’t want to use an extension
You may have a situation where you download image files to the app when the user visits a particular part of the app.
Once downloaded, it makes more sense to use the image on the device, as opposed to downloading it again.
My solution was to use a little bit of javascript, a webviewer with webviewstring, a clock and some logic.
Works with webviewer not visible as well
I also used the file component to install the html file needed to the sdcard
Default location is file:///mnt.sdcard, but subdirectories work too, if the additional path is added
My example simply check for an image file, and if it exists displays it, along with a message.
If the file doesn’t exist, displays a different “Sorry” image in the app, and a message.
Developers will be able to apply their own logic, so that if the file is not on the device, it
can be downloaded from online resources.
Most of the components used are likely to already be in an app whilst developing, so often simply a matter of reuse
BLOCKS
Please note, in production, for the filepath for the initial webviewstring and for the “else” setting of Image1.Picture
you may not need to include “file:///mnt/sdcard”.
Also you can create a specific directory on the sdcard when you create the html file in Screen Initialise.

HTML


Credits: in html

aia attached :) TestForFile

Enjoy!

ApInventor: HOWTO: Get Data from Private Google Sheet with A Google WebApp

I have done this before in another HOWTO: Download Google Sheet as CSV

but this one uses an intermediary Google Apps Script Web App to grab the data
This example uses a google sheet set as accessible only to me and the standalone
google apps script is set similarly. The script runs as me, but can be used by anyone
The app calls the script using the web component, then the script returns the specified
data to the app, which can then be used as a master list, and manipulated thereon
The example shows all the data retrieved, and then offers a spinner to choose a name
from the master list, and shows the email associated with the name
I used the obsfuscated text block for the script link.
Benefits:
  • protects your spreadsheet itself
  • allows anyone to access the data needed for the app, while not storing it on the app
  • easy data manipulation using the lists facility in the app
  • provides a pseudo api solution for other platforms and variants (e.g. Thunkable X at the time of writing)
  • impress your friends 😉
SPREADSHEET

note: I grabbed some dummy data from Mockaroo useful for this sort of thing

SCRIPT

I won’t go into detail about how to create a google apps script web app, well enough covered elsewhere


BLOCKS

Note the work done with the spinner. In the Web.gottext block I replace the first item in the list with the “header” text i want for the spinner.

I use Jorg Kowalski’s development of my spin on resetting the spinner

SCREENSHOT

aia attached – should work using the spreadsheet and script I have set up, or create your own

Ai2GoogleSheetWebApp