App Inventor and embedded HTML/JavaScript


How to get some Device specific info with App Inventor

Note: with the extension feature, this workaround is now obsolete. Thank you MIT!
Now you can use my Telephony Manager Extension instead.

This example provides the device specific info Android Version, Language and Device type using an embedded HTML/JavaScript document which supplies some info from the Navigator object.

The HTML file info.html is uploaded as asset to App Inventor.

There is one special thing to consider for HTML documents uploaded as assets into App Inventor: During development, you have to use the development path to the embedded HTML document.

file:///mnt/sdcard/AppInventor/assets/info.html


Before packaging the app, use the production path.

file:///android_asset/info.html


You probably also might be interested in the example How to get the Device ID within App Inventor calling a Java app

and How to get the Phone Number of the Device with App Inventor .

Note: Andrea found an alternative way to detect the language of a device with the text-to-speach component,
how it works, see here. Thank you Andrea!

App Inventor Blocks

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

Screenshots for HTC Desire and Nexus 5

Screenshot for Samsung Galaxy Tab 10.1N

HTML/JavaScript

<!doctype html>
<head>
  <meta name="author" content="puravidaapps.com">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <title>Info</title>
</head>

<body>
  <script type="text/javascript">
    // print the result to the page title
    window.document.title = navigator.appVersion + ";language=" + navigator.language;
  </script>
  
</body>
</html>

Questions and Answers

Q1: I have a problem with the select list item block. When I first time open the my app I see a error message "Select list item: Attempt to get item number 2 of a list of length 1".
A: try to add an else if length of list get listResult > 2 statement.

Q2: Both, file:///android_asset/info.html and file:///mnt/sdcard/AppInventor/assets/info.html don't exist, what can I do now?
A: You have to upload a file called info.html as asset into App Inventor for this to work. You can create the file info.html from my example or you can create it yourself (see chapter HTML/JavaScript above).

Test

Tested successfully on HTC Desire running Android 2.2, Samsung Galaxy Tab 10.1N running Android 3.2 and Nexus 5 running Android 5.0.1.

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 aia file for App Inventor
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