App Inventor Extensions: Tools | Pura Vida Apps

App Inventor Extensions


Tools Extension

See the App Inventor Extensions document about how to use an App Inventor Extension.

For questions about this extension, bug reports and feature requests, please start a new thread in the App Inventor Extensions forum. Thank you.

Nov 14th, 2015: Version 1 of the Tools Extension released for App Inventor version ai2extensions6 and Companion version 235.cdk2.

Dec 9th, 2015: Version 2 released: new blocks added to create HmacSha1 and HmacSha256 hashes.

April 14th, 2016: Version 3 released: new blocks added to show/hide the System User interface and to get a list of available sensors.

April 29th, 2016: Version 4 released: new block VersionCode added.

May 9th, 2016: Version 5 released: new event ActivityStateChanged added.

May 25th, 2016: Version 6 released: new method ShowKeyboard added.

July 19th, 2016: Version 7 released: new method ClearCache added.

Aug 3rd, 2016: Version 8 released: new methods Xor and XorHex added.

Aug 7rd, 2016: Version 9 released: 5 new properties added.

Aug 11th, 2016: Version 9a: avoid DX execution failed error: build each extension separately

Aug 13th, 2016: Version 9d: fix NavigationBarColor method, HideContent method added

Sep 07th, 2016: Version 10: Base64Encode method added

Nov 29th, 2016: Version 11: Matches method added

Jan 10th, 2017: Version 12: KeepScreenOn method added

Feb 20th, 2017: Version 13: VersionName, EmailAddressIsValid, PathToAssets methods added

Feb 23th, 2017: Version 14: Density method added

Description

A collection of several tools, which do not need additional permissions.

Properties


Set status bar color. This will work starting from API Level 21 (Android Lollipop).
Sponsor of this block is Klaus. Thank you!


Set navigation bar color. This will work starting from API Level 21 (Android Lollipop).
Use this property together with the method HideContent, see note below.
Sponsor of this block is Klaus. Thank you!

Note: As Peter found out here, after selecting About this app from the options menu and coming back to the screen, the screen size changed and the content now is able to move behind the navigation bar. Unfortunately we do not have any influence on what the options menu or the About this app button is doing. Therefore I now added a new method HideContent, which enables the content to move behind the status and navigation bars after using that method. Now you can add a dummy label on top for the status bar and on bottom for the navigation bar as additional margin, so in the end the screen looks like expected.


Set title color.
Sponsor of this block is Klaus. Thank you!


Returns the country/region code of the current Locale, which should either be the empty string, an uppercase ISO 3166 2-letter code, or a UN M.49 3-digit code.
A Locale object represents a specific geographical, political, or cultural region.
Sponsor of this block is Klaus. Thank you!


Returns the language code of the current Locale.
A Locale object represents a specific geographical, political, or cultural region.
Sponsor of this block is Klaus. Thank you!


Returns whether Warning Message should be suppressed.


Specifies whether Warning Message should be suppressed.

Methods


Base64 encode a string.
This method uses the flag NO_WRAP, i.e. to omit all line terminators (i.e., the output will be on one long line).
Precondition to use this block: Min Android API Level of the app must be 8 (Android Version 2.2)! You can adjust this in the manifest of the app.
Sponsor of this method is Near. Thank you!


Returns the density of the device. For more information see here.
See here for an example how to use that method.


Returns true, if it is a valid email address, else false. Details about the logic used.


Gallery Refresh for a specific filename. Returns the filename. I'm using the following snippet. Thank you Petrus!

Why do we need this?
Currently after drawing something and saving the canvas, the drawn image does not appear in the gallery of the device. It appears only after rebooting the device or using an app like Gallery Refresh, but that app only works for older Android versions. The new block "GalleryRefresh" fixes that issue for all Android versions.


Returns a base64 encoded HMAC SHA1 hash.
Precondition to use this block: Min Android API Level of the app must be 8 (Android Version 2.2)! You can adjust this in the manifest of the app.
What is a HMAC Sha1 hash?


Returns a base64 encoded HMAC SHA256 hash.
Precondition to use this block: Min Android API Level of the app must be 8 (Android Version 2.2)! You can adjust this in the manifest of the app.
What is a HMAC Sha256 hash?


Hide content, i.e. enable content to move behind status and navigation bar.
Use this method together with the property NavigationBarColor, see note there.


Hide the system user interface


Show the system user interface


Returns a list of available sensors


Returns the path to the assets. This method is useful, if you want to access files from the webviewer component stored in the assets of the app. The method will return file:///android_asset/ in case tha app is running after building the app as apk file and will return file:///mnt/sdcard/AppInventor/assets/ in case the app is running inside the companion app (development mode).


Returns the version code of the app
Note: if you run this block in the companion app, the version code of the companion app will be returned. After building your app, the version code of your app will be returned.


Returns the version name of the app
Note: if you run this block in the companion app, the version name of the companion app will be returned. After building your app, the version name of your app will be returned.


Show the keyboard


Clear the cache of the current app.
Returns true if clearing was successful, else false.
Sponsor of this method is Antonio. Thank you!


Exclusive or for boolean: returns true only when inputs differ (one is true, the other is false).


Exclusive or for hex strings, returns hex result. Strings must have the same length.


Returns true, if string matches a regular expression, else false.
Sponsor of this method is RuralAccent.com. Thank you!


As long as this window is visible to the user, keep the device's screen turned on and bright.
Note: If the screen of the device is on, this will obviously drain battery of your device! Please use this method wisely! You might want to use this method together with the Settings extension to adjust the brightness of the screen.
Sponsor of this method is Joerg. Thank you!

Events


Event indicating that the state of the activity changed.
Possible values are pause, stop and resume. See also the activity lifecycle.
Unfortunately it seems to be not possible to catch the 'onDestroy' activity state...

Example App: Save Canvas and Gallery Refresh Demo



Drawing something onto the canvas


Clicking the button to save and refresh


Opening the Gallery and the drawn image is there

Example Use of Hash blocks


Example App: Hide/Show System User Interface




Example App: ActivityStateChanged



Example App: ShowKeyboard

Example Use of ClearCache blocks

Example Use of Xor and XorHex blocks


Example Use of StatusBarColor, NavigationBarColor and TitleColor blocks (for devices running on Android 5+)

using the project A Better Color Picker by Italo.Thank you!


Example Use of Matches block

Use the Matches block to do some data validation, for example check for valid MAC addresses, or valid email addresses, endless possibilities... What are Regular Expressions?

So for example to check for valid MAC addresses, you can use this regular expression ^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$ found at stackoverflow.com. You can use an online regex validator, for example regex101.com to check your regex.


Sponsor of this method is RuralAccent.com. Thank you!

Example Use of KeepScreenOn block

Up to now we had to use workarounds to prevent the device from sleeping. Now this is not necessary anymore!

Questions and Answers

Q1: My question is whether it is possible to decrypt a text which is encrypted with this extension?
A: There is a fundamental difference between Hashing and Encryption algorithms, see this stackoverflow answer: Hashing is one way. You can not get your data/string from a hash code. Encryption is 2 way - you can decrypt again the encrypted string if you have the key with you. Also take a look at the other answers, which explain the differences a bit more. So the answer is "no", because this is Hashing and not Encryption, but you can use my AES extension to encrypt and decrypt.

Q2: How can I show de keyboard after starting a screen automatically?
A: Use the ShowKeyboard method. Because of the Screen Initialize timing issue, you have to use that method a few milliseconds later after screen initialize, you can use a clock component for that.

Do you need help with your App Inventor project?

I can help you: for one hour I charge 25 USD.
Please contact me at info [at] puravidaapps [dot] com for details!
For questions about App Inventor, please use the App Inventor forum. Thank you.

Terms and Conditions

Download


If you find this example helpful and you are using it in one of your projects,
be nice and donate a small amount!

Donation amount:

or donate some mBTC to Bitcoin Address:
1Jd8kXLHu2Vkuhi15TWHiQm4uE9AGPYxi8
Bitcoin

Thank you! Taifun
 

Download TaifunTools extension (aix file)

Download Save Canvas and Gallery Refresh Demo (aia file)
Download Show/Hide Demo (aia file)
Download ActivityStateChanged Demo (aia file)
Download ShowKeyboard Demo (aia file)
Download the modified 'A Better Color Picker' project (aia file)
Download the Matches test project (aia file)

Back to top of page ...

Creative Commons License
This work by Pura Vida Apps is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License
with attribution (name=Pura Vida Apps and link to the source site) required.


Home | Snippets | Tutorials | Extensions | News | Forums | Links | Search | Contact