Introduction
A non-visible extension that gets some information of the user's device.
Collaborators: @StarredStare
Big thanks to (no ranking order): @Taifun, @oseamiya, @Aquib_Khan, @Developer, @AyProductions, @Kumaraswamy, @Salman_Dev, Zhanqs, @StarredStare, @Ronald
Beta-testers: @Ronald
BIG shoutout to the 11 users you see above, I couldn't do it without you guys!
Package name: com.gordonlu.device.aix
Date: 2021-12-29T16:00:00Z
Last update: 2022-02-13T02:25:00Z
MINIMUM API LEVEL: 21 (Android 5.0 Lollipop )
REQUIRES: AndroidX support.
Special blocks which minimum API levels go beyond this range will be noted, e.g. SecurityPatch.
For the source code, PM me.
Version: 24
Before you use this extension...
Make sure to read this tutorial so that you won't mess things up.
Available Blocks
Blocks Documentation
Event blocks
GotChargingTime
Triggered when finished calculating the remaining charging time. Returns -1 when an error has occurred.
Parameters: time = long
Method blocks
ApplicationLastUpdatedTime
Returns the last updated time from the given package name. The unit is milliseconds after 1970.
Returns: 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 currently 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
orFULL
.Returns: text
BatteryTechnology
Returns the battery technology.
Returns: text
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
.Returns: number (int)
Parameters:
hexColor
= textNote: When I say a hex color, I do not include hexadecimal values. Thank you very much.
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: string
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 = double, longitude = double
GetCountryName
Returns the name of the country from the given latitude and longitude.
Returns: string
Parameters: latitude = double, longitude = 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 = double, longitude = double
GetStreetAddress
Returns the street address from the given latitude and the longitude.
Returns: string
Parameters: latitude = double, longitude = 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. I used emulator examples in this Stack Overflow answer.
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: text
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 available 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 name of the device.
Returns: text
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.
Note: I will NOT show the Do-It for this block because the Do-It is way too much. See below for an example of what result it will return:
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. (Remember that the status bar color of the App Inventor Companion is dark green.)
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 = string
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 name of an app 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
Returns the Android version of the phone.
Returns: string
BaseOS
Returns the base OS build the product is based on.
Returns: text
BatteryCharging
Returns true if the device is charging, else false.
Returns: boolean
CpuTemperature
Returns the CPU temperature of the device.
*Returns: number (float)
This is an Open Source property.
Incremental
Returns the internal value used by the underlying source control to represent this build.
Returns: text
Release
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
Returns the current development codename, or the string 'REL' if this is a release build.
Returns: text
SdkVersion
Returns the SDK version of the software currently running on this hardware device.
Returns: number (int)
SecurityPatch
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 APIs > 22 (Android 6.0 or larger).
Returns: text
Open Source / Others
How do you calculate the CPU temperature?
- Import these:
import java.io.BufferedReader;
import java.io.InputStreamReader;
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?
Import this:
import android.os.Build.VERSION;
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";
}
}
Feel free to copy the codes and add it to your extension!
How about the 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
}
]
Tests
Tested successfully on Xiaomi 11 5G NE (Android 11, SDK 30), Google Pixel 5 Emulator (Android 11, SDK 30) and Google Pixel 4 Emulator (Android 10, SDK 29).
Tested unsuccessfully with the App Inventor emulator.
Downloads
TXT: not available yet, see my poll in the next posts.
AIX:
com.gordonlu.device.aix (42.5 KB)
AIA files:
Customizer.aia (62.3 KB) to use this extension to deal with colors of the device.
Used extensions in AIA files:
- ColorPickerDialog by Zhangqs
Rate my extension!
- Good extension!
- Bad extension.
Made with Niotron IDE.
Kindly PM me if you have any questions! Also, if you like my extension, please like it! It takes some effort for me to make it...
Votes and likes tell me the general user feedback of my extension. If you read this extension, please take 20 seconds to drop by and give a vote / like!
Added to my website on January 1, 2022.
HAPPY 2022!
If you have any features that you want to add and you know the code, PM me.
Gordon Lu