Device (extension)

Extension published on January 1, 2022

🏷️ Tags: #extensions

A non-visible extension that gets some information of the user's device.

Made with Niotron IDE at https://ide.niotron.com.

Current version: 23 Package name: com.gordonlu.device.aix

🍭 Minimum API: 21 (Android 5.0 Lollipop) [note: some special blocks require API above that. Read the documentation.]

For more information, read this MIT App Inventor Community thread.

βš™οΈ This extension only supports builders that allow AndroidX extensions, e.g., MIT App Inventor, Kodular. To find out whether your builder has AndroidX support, contact the builder team.

πŸ“– Documentation

Event blocks

GotChargingTime - Triggered when finished calculating the remaining charging time. Returns -1 when an error is occured.

Parameters: time = number (long)

Method blocks

ApplicationLastUpdatedTime - Returns the last updated time from the given package name. The unit is milliseconds after 1970. Returns: number (long)

Parameters: packageName = text

ApplicationName - Returns the application name from the given package name, else returns the notFound value. Returns: text

Parameters: packageName = text, notFound = text

AppPackageName - Returns the package name of the current running application. Returns: text

ApplicationSpecificDirectory - Returns an absolute path of the application specific directory. Returns: text

BatteryCapacity - Returns the battery capacity. Returns: number (double)

BatteryHealth - Returns the health value of the phone's battery. Can be: UNKNOWN, GOOD, OVERHEAT, DEAD, OVER_VOLTAGE, UNSPECIFIED_FAILURE, COLD. Returns: text

BatteryPercentage - Returns the battery level in percentage. Returns: number (int)

BatteryPluggedSource - Returns the device the phone is plugged to. Can be 'USB', 'AC', 'WIRELESS' or 'UNKNOWN'. Returns: text

BatteryStatus - Returns the current status of the phone's battery. Can be: UNKNOWN, CHARGING, DISCHARGING, NOT_CHARGING or FULL. Returns: text

BatteryTechnology - Returns the battery technology. Returns: number (int)

BatteryVoltage - Returns the current battery voltage. Returns: number (int)

Board - Returns the name of the underlying board, like goldfish. Returns: text

Bootloader - Returns the system bootloader version number. Returns: text

Brand - Returns the consumer-visible brand with which the product/hardware will be associated, if any. Returns: text

CacheDirectory - Returns the absolute path of the cache directory of the application. Returns: text

ColorConvertHexToInt - Convert a hex color to a integer color. The result is returned as integer. This function does not support shorthand hex values like #000. The expected parameter for hexColor is something like #FFFFFF. This does not include hexadecimal values. Returns: number (int)

Parameters: hexColor = text

ColorConvertIntToHex - Convert a integer color to a hex color. The result is returned as string. Returns: number (int)

Parameters: intColor = number (int)

CurrentLatitude - Returns the user's current latitude. Returns: number (double)

Note: I tested this block with the LocationSensor, and found that this block is a bit faster than that. You can use both of them in the app, but I would not suggest you because this is available with built-in blocks.

CurrentLongitude - Returns the user's current longitude. Returns: number (double)

Note: I tested this block with the LocationSensor, and found that this block is a bit faster than that. You can use both of them in the app, but I would not suggest you because this is available with built-in blocks.

DeviceId - Returns the device ID. Returns: text

DisableBluetooth - Turns off Bluetooth without user interaction.

Display - Returns a build ID string meant for displaying to the user. Returns: text

DisplayCountry - Returns a name for the locale's country that is appropriate for display to the user. Returns: text

DisplayFontScale - Returns the font scale of the display. Returns: number (float)

DisplayHeight - Returns the display height of the device. Returns: number (int)

DisplayLanguage - Returns a name for the locale's language that is appropriate for display to the user. Returns: text

DisplayPhysicalSize - Returns the physical size of the device. Returns: number (double)

DisplayRefreshRate - Returns the refresh rate of the display in frames per second. Returns: number (float)

DisplayRotation - Returns the rotation of the screen from its "natural" orientation. The returned value may be Surface.ROTATION_0 (no rotation), Surface.ROTATION_90 , Surface.ROTATION_180 , or Surface.ROTATION_270 . For example, if a device has a naturally tall screen, and the user has turned it on its side to go into a landscape orientation, the value returned here may be either Surface.ROTATION_90 or Surface.ROTATION_270 depending on the direction it was turned. The angle is the rotation of the drawn graphics on the screen, which is the opposite direction of the physical rotation of the device. Returns: number (int)

DisplayScreenTimeout - Returns the screen timeout time of the device. Returns: number (int)

DisplayScript - Returns a name for the the locale's script that is appropriate for display to the user. Returns: text

DisplayWidth - Returns the display width of the device. Returns: number (int)

EnableBluetooth - Turns on Bluetooth without user interaction.

ExternalStorageAvailable - Returns the available storage size in bytes. Returns: number (long)

ExternalStorageTotal - Returns the total amount of external storage in bytes. Returns: number (long)

ExternalStorageUsed - Returns the used amount of external storage in bytes. Returns: number (long)

Fingerprint - Returns the fingerprint of the device. Returns: text

GetBatteryChargingTime - Attempts to calculate the remaining charging time and triggers the GotChargingTime event.

GetCity - Returns the city name from the given latitude and the longitude. Returns: string

Parameters: latitude = number (double), longitude = number (double)

GetCountryName - Returns the name of the country from the given latitude and longitude. Returns: string

Parameters: latitude = number (double), longitude = number (double)

GetIpAddress - Returns the IP address of the device. Returns: text

Parameters: useIpV4 = boolean

GetLuminanceOfColor - Returns the relative luminance of a color. This block only supports devices above or Android 8.0. Returns: number (float)

Parameters: color = number (long)

GetMacAddress - Returns the MAC address(media access control address) of the device. Returns: text

GetNumberOfCores - Returns the number of processors available to the Java virtual machine. Returns: number (int)

GetPostalCode - Returns the postal code from the latitude and the longitude. Returns: string

Parameters: latitude = number (double), longitude = number (double)

GetStreetAddress - Returns the street address from the given latitude and the longitude. Returns: string

Parameters: latitude = number (double), longitude = number (double)

Hardware - Returns the name of the hardware (from the kernel command line or /proc). Returns: text

Home - Returns to the home screen of the application. Your application is not closed.

Id - Returns either a changelist number, or a label like M4-rc20. Returns: text

InstallationFromAppStore - Returns the package name of the app that has installed your application. Returns: text

InstalledApplications - Returns a list of installed applications. Returns: list

InternalMemoryAvailable - Returns the available internal memory in bytes. Returns: number (long)

InternalMemoryTotal - Returns the total internal memory size in bytes. Returns: number (long)

InternalMemoryUsed - Returns the used internal memory size in bytes. Returns: number (long)

IsAdbDebuggingEnabled - Returns true if ADB debugging is enabled, which might be a sign of users hacking your app. Returns: boolean

IsAirplaneModeEnabled - Checks if the airplane mode of the device is on. Returns: boolean

IsBatteryPresent - Indicating whether a battery is present. Returns: boolean

IsCameraAvailable - Returns true if the device's camera is available, else false. Returns: boolean

IsDarkColor - Returns true if the color is dark, else it returns false, means the color is light. The result is returned as boolean. Returns: boolean

Parameters: color = number (int) / color

IsDateAndTimeAutomatic - Checks if 'Automatic Date and Time' is enabled in Settings. Returns: text

IsEmailAddressValid - Tests if the email address is valid. Returns: boolean

Parameters: emailAddress = text

IsEmulator - Checks if the app is operating on an emulator. This does not work on an App Inventor emulator. Returns: boolean

IsExternalMemoryAvailable - Checks if external memory is available. Returns: boolean

IsFlashAvailable - Returns true if the device has a flashlight, else false. Returns: boolean

IsHdrCapable - Returns whether the screen has a high dynamic rate. This only works in versions larger or Android 8. Returns: boolean

IsInstalledFromPlayStore - Tests if the application is installed from Google Play Store. Returns: boolean

IsNightModeActive - Checks if the night mode of the device is on. Returns: boolean

Iso3Country - Returns a three-letter abbreviation for this locale's country. If the country matches an ISO 3166-1 alpha-2 code, the corresponding ISO 3166-1 alpha-3 uppercase code is returned. If the locale doesn't specify a country, this will be the empty string. Returns: string

Iso3Language - Returns a three-letter abbreviation of this locale's language. If the language matches an ISO 639-1 two-letter code, the corresponding ISO 639-2/T three-letter lowercase code is returned. The ISO 639-2 language codes can be found on-line, see "Codes for the Representation of Names of Languages Part 2: Alpha-3 Code". If the locale specifies a three-letter language, the language is returned as is. If the locale does not specify a language the empty string is returned. Returns: string

IsScreenRound - Return whether the screen has a round shape. Apps may choose to change styling based on this property, such as the alignment or layout of text or informational icons. Returns: boolean

IsScreenWideColorGamut - Return whether the screen has a wide color gamut and wide color gamut rendering is supported by this device. When true, it implies the screen is colorspace aware but not necessarily color-managed. The final colors may still be changed by the screen depending on user settings. Returns: boolean

IsSdCardAvailable - Checks whether the SD card is available. Returns: boolean

IsSmsCapable - Returns true if the current device supports SMS service. Returns: boolean

KernelVersion - Returns the Kernel version of the device. Returns: string

LanguageTag - Returns a well-formed IETF BCP 47 language tag representing this locale. Returns: text

Manufacturer - Returns the manufacturer of the product or hardware. Returns: text

MemoryFree - Returns the total RAM on the device in bytes. Returns: number (long)

MemoryTotal - Returns the total RAM on the device in bytes. Returns: number (long)

MemoryUsed - Returns the used RAM on the device in bytes. Returns: number (long)

ModelName - Returns the end-user-visible name for the end product.

NavigationBarHeight - Returns the height of the navigation bar of the device. Returns: number (int)

NumberOfCameras - Returns the number of cameras available on the device. Returns: number (int)

NumberToString - Converts a number to a string.Returns: text

Parameters: number = number (int)

Product - Returns the name of the overall product. Returns: text

SensorAmount - Returns the total amount of sensors on the device. Returns: number (int)

SensorList - Returns a list of all sensors on the device. Returns: list

SetNavigationBarColor - Resets the navigation bar color to the given color.

Parameters: color = color

SetStatusBarColor - Resets the status bar color to the given color.

Parameters: color = color

SetStatusBarColorDefault - Sets the status bar color to the default color of the application or transparent.

SimCountryIso - Returns the ISO-3166-1 alpha-2 country code equivalent for the SIM provider's country code. Returns: text

SimOperator - Returns the MCC+MNC (mobile country code + mobile network code) of the provider of the SIM. 5 or 6 decimal digits. Returns: text

SimOperatorName - Returns the Service Provider Name (SPN). Returns: text

StringToNumber - Converts a string to a number. Returns: number (int)

Parameters: string = text

Supported32BitAbis - Returns a list of 32 bit ABIs supported by this device. The most preferred ABI is the first element in the list. Requires Android 5 or higher. Returns: list

Supported64BitAbis - Returns a list of 64 bit ABIs supported by this device. The most preferred ABI is the first element in the list. Requires Android 5 or higher. Returns: list

SupportedAbis - Returns a list of ABIs supported by this device. The most preferred ABI is the first element in the list. Requires Android 5 or higher. Returns: list

Tags - Returns comma-separated tags describing the build, like 'unsigned,debug'. Returns: text

TextToHexadecimal - Turns a string value into a hexadecimal value. Returns: string

Parameters: string = text

Time - The time at which the build was produced, given in milliseconds since the UNIX epoch. Returns: number (long)

Type - Returns the type of build, like 'user' or 'eng'. Returns: text

VersionCodeFrom - Returns the version code from the package name. In case an error occurs, the notFound value is returned. Returns: number (int)

Parameters: packageName = text, notFound = text

VersionNameFrom - Returns the version code from the package name. In case an error occurs, the notFound value is returned. Returns: number (int)

Parameters: packageName = text, notFound = text

Property blocks

AndroidVersion (blocks-only, read-only) - Returns the Android version of the phone. Returns: string

*This is an Open Source property.

BaseOS (blocks-only, read-only)- Returns the base OS build the product is based on. Returns: text

BatteryCharging (blocks-only, read-only)- Returns true if the device is charging, else false. Returns: boolean

CpuTemperature (blocks-only, read-only)- Returns the CPU temperature of the device. Returns: number (float)

*This is an Open Source property.

Incremental (blocks-only, read-only)- Returns the internal value used by the underlying source control to represent this build. Returns: text

Release (blocks-only, read-only)- Returns the user-visible version string. E.g., "1.0" or "3.4b5" or "bananas". This field is an opaque string. Do not assume that its value has any particular structure or that values of RELEASE from different releases can be somehow ordered. Returns: text

SdkCodeName (blocks-only, read-only)- Returns the current development codename, or the string 'REL' if this is a release build. Returns: text

SdkVersion (blocks-only, read-only)- Returns the SDK version of the software currently running on this hardware device. Returns: number (int)

SecurityPatch (blocks-only, read-only)- Returns the user-visible security patch level. This value represents the date when the device most recently applied a security patch. This block only works on API > 22 (Android 6.0 or larger). Returns: text

Open Source / Others

How do you calculate the CPU temperature?

  1. Import these:

import java.io.BufferedReader;

import java.io.InputStreamReader;

  1. Then use this:

@SimpleProperty(description = "Returns the CPU temperature of the device.")

public static float CpuTemperature () {

Process process;

try {

process = Runtime.getRuntime().exec("cat sys/class/thermal/thermal_zone0/temp");

process.waitFor();

BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));

String line = reader.readLine();

if(line!=null) {

float temp = Float.parseFloat(line);

return temp / 1000.0f;

} else {

return 51.0f;

}

} catch (Exception e) {

e.printStackTrace();

return 0.0f;

}

}

How do you find the Android Version of the device?

  1. Import this:

import android.os.Build.VERSION

  1. Then use this:

@SimpleProperty(description = "Returns the Android version of the phone.")

public String AndroidVersion () {

if (android.os.Build.VERSION.SDK_INT == 9) {

return "2.3";

} else if (android.os.Build.VERSION.SDK_INT == 10) {

return "2.3.3";

} else if (android.os.Build.VERSION.SDK_INT == 11) {

return "3.0";

} else if (android.os.Build.VERSION.SDK_INT == 12) {

return "3.1";

} else if (android.os.Build.VERSION.SDK_INT == 13) {

return "3.2";

} else if (android.os.Build.VERSION.SDK_INT == 14) {

return "4.0";

} else if (android.os.Build.VERSION.SDK_INT == 15) {

return "4.0.3";

} else if (android.os.Build.VERSION.SDK_INT == 16) {

return "4.1";

} else if (android.os.Build.VERSION.SDK_INT == 17) {

return "4.2";

} else if (android.os.Build.VERSION.SDK_INT == 18) {

return "4.3";

} else if (android.os.Build.VERSION.SDK_INT == 19) {

return "4.4";

} else if (android.os.Build.VERSION.SDK_INT == 20) {

return "4.4W";

} else if (android.os.Build.VERSION.SDK_INT == 21) {

return "5.0";

} else if (android.os.Build.VERSION.SDK_INT == 22) {

return "5.1";

} else if (android.os.Build.VERSION.SDK_INT == 23) {

return "6.0";

} else if (android.os.Build.VERSION.SDK_INT == 24) {

return "7.0";

} else if (android.os.Build.VERSION.SDK_INT == 25) {

return "7.1";

} else if (android.os.Build.VERSION.SDK_INT == 26) {

return "8.0";

} else if (android.os.Build.VERSION.SDK_INT == 27) {

return "8.1";

} else if (android.os.Build.VERSION.SDK_INT == 28) {

return "9";

} else if (android.os.Build.VERSION.SDK_INT == 29) {

return "10";

} else if (android.os.Build.VERSION.SDK_INT == 30) {

return "11";

} else if (android.os.Build.VERSION.SDK_INT == 31) {

return "12";

} else {

return "UNKNOWN";

}

}

How about the sample result for SensorList?

[

{

Sensor name="Proximity Sensor",

vendor="xiaomi Inc.",

version=1,

type=8,

maxRange=5.0,

resolution=1.0,

power=0.012,

minDelay=200000

},


{

Sensor name="icm4x6xx Accelerometer Non-wakeup",

vendor="TDK-Invensense",

version=307,

type=1,

maxRange=156.9064,

resolution=0.0047884034,

power=0.24,

minDelay=2000

},


{

Sensor name="ak0991x Magnetometer Non-wakeup",

vendor="akm",

version=146970,

type=2,

maxRange=4911.994,

resolution=0.15,

power=1.1,

minDelay=10000

}

]

How to enable and disable Bluetooth?

  1. Import this:

import android.bluetooth.BluetoothAdapter;

  1. Add this:

@UsesPermissions(permissionNames = "android.permission.READ_PRIVILEGED_PHONE_STATE, " + "android.permission.BLUETOOTH_ADMIN")

  1. Use this:

@SimpleFunction (description = "Turns on Bluetooth without user interaction.")

public void EnableBluetooth() {

BluetoothAdapter.getDefaultAdapter().enable();

}

@SimpleFunction (description = "Turns off Bluetooth without user interaction.")

public void DisableBluetooth() {

BluetoothAdapter.getDefaultAdapter().disable();

}

Downloads

Acknowledgements

Thanks to the following users for helping me in this extension or providing me ideas (no ranking).

@HEART12, @AyProductions, @Taifun, @oseamiya, @Aquib_Khan, @StarredStare, @Developer, KUMARSWAMY_B.G, @Salman_Dev, @Ronald, Zhangqs

YouTube Tutorials

This is a list of YouTube tutorials about this extension. Currently there are 2 videos launched.

PART 1 - BATTERY INFO

PART 2 - STORAGE INFO

TERMS AND CONDITIONS

By downloading or sharing my extension, you agree to follow these terms and conditions.

  1. Have fun using the extension!

  2. This, along with the MIT App Inventor original post above, are the only authorized places to download this extension. As an organization, you are not allowed to host and advertize this extension on your website, document, tweet, blog, article or any software you made without my authorization. You are also reminded not to include a direct download link of this extension on your website without my permission. If you are interested in the actions listed above, please contact me via email. Do remember that if you violate term no. 2, AICODE has the right to flag your website, document, tweet, blog or article as a violation of copyright, or other legal actions will be taken. Please contact me if you find anyone do this.

However, you can copy the link of this webpage and share it to someone as a personal identity (not as an organization), or sharing it on these authorized forums: App Inventor, Kodular, Niotron, Appzard and Android Builder communities. The term organization includes schools, markets and app stores, companies and social groups. Thank you for your understanding.

Those organizations are authorized to advertize or host my extension:

  • Kodular admins

  • MIT App Inventor admins

  • Pura Vida Apps / Taifun Baer

  1. Selling this extension/product to anyone is not allowed unless authorized by AICODE.

  2. These terms and conditions are written and issued on December 20, 2021. AICODE has the total permission to edit these terms and conditions anytime.