[FREE] Device πŸ’» - Get device info!

Introduction

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

Collaborators: @HEART12 , @AyProductions

Big thanks to: @Taifun, @oseamiya, @Aquib_Khan

I would like to thank my classmates Hayson Lee and Charmaine Wong for their special effort helping me with my extension.

:package: Package name: com.gordonlu.device.aix

:date: Date: 2021-12-29T16:00:00Z

For the source code, PM me.

Version: 17

Blocks Documentation

Method blocks

ApplicationLastUpdatedTime

image

Returns the last updated time from the given package name. The unit is milliseconds after 1970.

Returns: long

Parameters: packageName = text

ApplicationName

image

Returns the application name from the given package name, else returns the notFound value.

Returns: text

Parameters: packageName = text, notFound = text

BatteryCapacity

image

Returns the battery capacity.

Returns: number (double)

BatteryHealth

image

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

Returns: text

BatteryPercentage

image

Returns the battery level in percentage.

Returns: number (int)

BatteryPluggedSource

image

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

Returns: text

BatteryStatus

image

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

Returns: text

BatteryTechnology

image

Returns the battery technology.

Returns: number (int)

BatteryVoltage

image

Returns the current battery voltage.

Returns: number (int)

Board

image
Returns the name of the underlying board, like goldfish.

Returns: text

Bootloader

image
Returns the system bootloader version number.

Returns: text

Brand

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

Returns: text

ColorConvertHexToInt

image

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 = text

Note: When I say a hex color, I do not include hexadecimal values. Thank you very much.

ColorConvertIntToHex

image

Convert a integer color to a hex color. The result is returned as string.

Returns: number (int)

Parameters: intColor = number (int)

CurrentLatitude

image

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

image

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

image

Returns the device ID.

Returns: text

DisableBluetooth

image

Turns off Bluetooth without user interaction.

Display

image
Returns a build ID string meant for displaying to the user.

Returns: text

DisplayCountry

image

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

Returns: string

DisplayFontScale

image

Returns the font scale of the display.

Returns: number (float)

DisplayHeight

image

Returns the display height of the device.

Returns: number (int)

DisplayLanguage

image

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

Returns: text

DisplayPhysicalSize

image

Returns the physical size of the device.

Returns: number (double)

DisplayRefreshRate

image

Returns the refresh rate of the display in frames per second.

Returns: number (float)

DisplayRotation

image

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

image

Returns the screen timeout time of the device.

Returns: number (int)

DisplayScript

image

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

Returns: text

DisplayWidth

image

Returns the display width of the device.

Returns: number (int)

EnableBluetooth

image

Turns on Bluetooth without user interaction.

ExternalStorageAvailable

image

Returns the available storage size in bytes.

Returns: number (long)

ExternalStorageTotal

image

Returns the total amount of external storage in bytes.

Returns: number (long)

ExternalStorageUsed

image

Returns the used amount of external storage in bytes.

Returns: number (long)

GetCity

image

Returns the city name from the given latitude and the longitude.

Returns: string

Parameters: latitude = double, longitude = double

GetCountryName

image

Returns the name of the country from the given latitude and longitude.

Returns: string

Parameters: latitude = double, longitude = double

GetIpAddress

image

Returns the IP address of the device.

Returns: text

Parameters: useIpV4 = boolean

GetLuminanceOfColor

image

Returns the relative luminance of a color. This block only supports devices above or Android 8.0.

Returns: number (float)

Parameters: color = number (long)

GetNumberOfCores

image

Returns the number of processors available to the Java virtual machine.

Returns: number (int)

GetPostalCode

image

Returns the postal code from the latitude and the longitude.

Returns: string

Parameters: latitude = double, longitude = double

GetStreetAddress

image

Returns the street address from the given latitude and the longitude.

Returns: string

Parameters: latitude = double, longitude = double

Hardware

image

Returns the name of the hardware (from the kernel command line or /proc).

Returns: text

Id

image

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

Returns: text

InstallationFromAppStore

image

Returns the package name of the app that has installed your application.

Returns: text

InternalMemoryAvailable

image

Returns the available internal memory in bytes.

Returns: number (long)

InternalMemoryTotal

image

Returns the total internal memory size in bytes.

Returns: number (long)

InternalMemoryUsed

image

Returns the used internal memory size in bytes.

Returns: number (long)

IsAdbDebuggingEnabled

image

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

Returns: boolean

IsBatteryPresent

image

Indicating whether a battery is present.

Returns: boolean

IsCameraAvailable

image

Returns true if the device's camera is available, else false.

Returns: boolean

IsDarkColor

image

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

IsEmailAddressValid

image

Tests if the email address is valid.

Returns: boolean

Parameters: emailAddress = text

IsExternalMemoryAvailable

image

Checks if external memory is available.

Returns: boolean

IsFlashAvailable

image

Returns true if the device has a flashlight, else false.

Returns: boolean

IsHdrCapable

image

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

Returns: boolean

IsInstalledFromPlayStore

image

Tests if the application is installed from Google Play Store.

Returns: boolean

IsScreenRound

image

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

Iso3Country

image

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

image

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

KernelVersion

image

Returns the Kernel version of the device.

Returns: string

LanguageTag

image

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

Returns: text

Manufacturer

image

Returns the manufacturer of the product or hardware.

Returns: text

MemoryFree

image

Returns the available RAM on the device in bytes.

Returns: number (long)

MemoryTotal

image

Returns the total RAM on the device in bytes.

Returns: number (long)

MemoryUsed

image

Returns the used RAM on the device in bytes.

Returns: number (long)

ModelName

image

Returns the name of the device.

Returns: text

NavigationBarHeight

image

Returns the height of the navigation bar of the device.

Returns: number (int)

NumberOfCameras

image

Returns the number of cameras available on the device.

Returns: number (int)

NumberToString

image

Converts a number to a string.

Returns: text

Parameters: number = number (int)

Product

image

Returns the name of the overall product.

Returns: text

SensorAmount

image

Returns the total amount of sensors on the device.

Returns: number (int)

SensorList

image

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:

StringToNumber

image

Converts a string to a number.

Returns: number (int)

Parameters: string = text

Tags

image

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

Returns: text

TextToHexadecimal

image

Turns a string value into a hexadecimal value.

Returns: string

Parameters: string = string

Type

image

Returns the type of build, like 'user' or 'eng'.

Returns: text

VersionCodeFrom

image

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

image

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

image

Returns the Android version of the phone.

Returns: string

BaseOS

image

Returns the base OS build the product is based on.

Returns: text

BatteryCharging

image

Returns true if the device is charging, else false.

Returns: boolean

CpuTemperature

image

Returns the CPU temperature of the device.

*Returns: number (float)

This is an Open Source property.

Incremental

image

Returns the internal value used by the underlying source control to represent this build.

Returns: text

Release

image

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

image

Returns the current development codename, or the string 'REL' if this is a release build.

Returns: text

SdkVersion

image

Returns the SDK version of the software currently running on this hardware device.

Returns: number (int)

SecurityPatch

image
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?

  1. 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).

Tested unsuccessfully with the App Inventor emulator.

Downloads

TXT: not available yet, see my poll in the next posts.

AIX: com.gordonlu.device.aix (34.6 KB)

Rate my extension!

  • Good extension!
  • Bad extension.

0 voters


Made with Niotron IDE.

Kindly :email: PM me if you have any questions! Also, if you like my extension, please :heart: 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.

16 Likes

Device.Id is returning the android OTA update version. It is not a device ID.
e.g.
https://developers.google.com/android/images#sunfish

1 Like

I didn't say that's the ID of the device.

I must be seeing things then :wink:

image

2 Likes

Version 2

New blocks:

image

Bootloader

image
Returns the system bootloader version number.

Returns: text

Tags

image
Returns comma-separated tags describing the build, like 'unsigned,debug'.

Returns: text

This is how you convert text to a list.

image

1 Like

You can also add blocks like processor or android version!

1 Like

nice extension

1 Like

Version 3!

New blocks:

image

SdkCodeName

image
Returns the current development codename, or the string 'REL' if this is a release build.

SdkVersion

image
Returns the SDK version of the software currently running on this hardware device.

1 Like

is it possible to join the results of all these blocks and calculate the MD5 as a unique id of the device?

I'm not sure yet.

Thank you for adding my (at least 1) block suggestions @gordon_lu

1 Like

Nice...

did u use Google developer

1 Like

Yes I did.

Version 4 updated!

New blocks:

Documentation

BaseOS

image
Returns the base OS build the product is based on.

Returns: text

Incremental

image
Returns the internal value used by the underlying source control to represent this build.

Returns: text

SecurityPatch

image
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

2 Likes

This update is cool!

1 Like

@Gordon_Lu it is possible to return IMEI in Android 11?

Try this extension by @Aquib_Khan.

2 Likes

Should I make this Open Source?

  • Yes, make this open source!
  • No, don't do that.

0 voters

On January 7 next year, I will check the poll to see what I'm going to do.

2 Likes

Thanks... :+1::+1::pray:

2 Likes

Do you mean 2022 ? :sweat_smile:

2 Likes