Englisch version   Deutsche Version


Version Anpassungen
1.0 (2020-02-29 Initial version
2.0 (2020-08-18) - Renamed to UrsAI2Util
- Method MoveTaskToBackground added
- Method SimulateHomeKey added
- Event OnDestroy removed, raising of events in Form.onDestroy is not supported
2.1 (2020-10-27) Method FileListFromAssets added.

Content

Download

Usage

Events onPause, onStop, onResume

StringToHex

Image-Import

Other functions

Tools

Download

The ZIP archive UrsAI2Utils for downloading. The archive contains the source code and the compiled binary and a sample project to upload to the App Inventor.

Usage

The extension provides functions for three functional areas.

Events onPause, onStop, onResume

The following graphic shows the life cycle of an Android Activity.

State diagram for an Android Activity Lifecycle.

For some applications it can be interesting to know the state of the app. The extension provides events that are triggered when the state changes. Unfortunately, only four of these changes can be accessed via the App Inventor Framework. onCreate is already implemented in the screen component as Initialize. onPause, onStop, onResume are provided by this extension.

Block Funktion
Initialize The Initialize event is run when the Screen starts and is only run once per screen.
onPause The app is (partially) covered. User input is not accepted.1)
onStio The app is moved to the background.
onResume The app becomes visible and accepts user input.

1) In all my attempts at these events, onStop was always triggered after onPause.


StringToHex

This function should make debugging easier. Especially for data exchange purposes it can be interesting to know what the internal representation of a String is. Usually it is UTF-8 coded.

Block Funktion
ConvertToHexString The string in the argument Text is converted to a string that contains the hexadecimal representation of the individual characters. e.g. "abcß" becomes "61 62 63 C3 9F".
 

Image-Import

Mit der MQTT-Extension lassen sich Byte-Arrays übertragen, dies können z.B. auch JPEG-Images sein. Die Methode konvertiert das Empfange Byte-Array in ein Bitmap-Objekt und zeigt es auf einem im App Inventor enthaltenen Komponente Image an. Diese Methode darf nicht mit der Eigenschaft Picture der Komponente verwechselt werden! Picture erwartet den Dateipfad auf eine Image-Datei.

Byte arrays can be transferred with the MQTT extension, e.g. this may be JPEG images. The method converts the received byte array into a bitmap object and displays it on an App Inventor Image component. This method should not be confused with the Picture property of the component! Picture expects the file path to an image file.

Block Funktion
Image-Import JPEG: Byte array that contains a JPEG image.
ImageBlock: A component of the type Image on which the image is to be displayed.
Rotation: Rotation angle.

A typical use of the block could look like this:

Verwendung JPEGtoImageBlock


Other functions

Block Funktion
Moves the app to the background.
Simulates pressing the home button.
Returns a list of the asset file names with the specified extension.
"*" return all.

Tools

For developing own extensions I gathered some tips: AI2 FAQ: Develop Extensions.