App Inventor Extensions


Tools Extension

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

For questions about this extension or bug reports please start a new thread in the App Inventor community. Thank you.

For feature requests please contact me by email. To be a sponsor of a new method already is possible starting from only 10 USD! With your contribution you will help the complete App Inventor community. 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

Jul 5th, 2017: Version 15: PackageName and IsDevelopment method added, see note below

Jul 12th, 2017: Version 16: Sha256 hash method added, see note below

Jul 16th, 2017: Version 16a: new logic for GalleryRefresh method, see note below

Note: using the extension version 15, 16 or 16a together with another Pura Vida Apps extension built between July 1st and July 20th might result in error message Unable to find TaifunTools component while opening a project. Use extension version 16b instead.

Jul 21th, 2017: Version 16b: new build using extension-specific directory in aix file, "More Information" link updated in extension description

Aug 12th, 2017: Version 17: DontKeepScreenOn method added

Sep 6th, 2017: Version 18: ApiLevel method added

May 5th, 2019: Version 19: ApplicationSpecificDirectory method added

Jan 1st, 2020: Version 20: ClearAppData method added

Oct 21st, 2020: Version 21: PathToAssets updated for API Level 29+ as well as for the Kodular companion app

Jan 6th, 2021: Version 21a: bugfix PathToAssets method

Mar 25th, 2024: Version 22: PathToAssets removed, IsPermissionGranted 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!

Note: the StatusBarColor, NavigationBarColor and TitleColor blocks might not work on all Android versions or App Inventor distributions, see also here.


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.

Note: the StatusBarColor, NavigationBarColor and TitleColor blocks might not work on all Android versions or App Inventor distributions, see also here.


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

Note: the StatusBarColor, NavigationBarColor and TitleColor blocks might not work on all Android versions or App Inventor distributions, see also here.


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


Returns the API Level of the device.
Sponsor of this method is Johannes. Thank you!


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.


Returns true, if app is running in development mode (using the companion app), else returns false.


Gallery Refresh for a specific filename. Note: you will have to use an absolute path to the file, for example /storage/emulated/0/DCIM/myImage.jpg, 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?


Returns a Sha256 hash of a given string.
Sponsor of this method is Adrian. Thank you!


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 package name of the app
Note: if you run this block in the companion app, the package name of the companion app will be returned. After building your app, the package name of your app will be returned.


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!


Calling this method will cancel the KeepScreenOn flag.


Checks, if a specific permission is granted. Returns true or false.

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!

Note: the StatusBarColor, NavigationBarColor and TitleColor blocks might not work on all Android versions or App Inventor distributions, see also here.


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.

For questions about App Inventor,
please ask in the App Inventor community.Thank you.

Terms and Conditions

Download


Developing and maintaining snippets, tutorials and extensions for App Inventor takes a lot of time.
I hope it saved some of your time. If yes, then you might consider to 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 | Links | Search | Privacy Policy | Contact