nice update!
I tested your extension and it's working
This extension is now added to my website.
I realized that this extension does not work on the App Inventor emulator.
When I added this component to the project, it gave me a huge, unreasonable runtime error, so don't test it with the eumlator.
Error from Companion: java.lang.RuntimeException: invalid syntax in eval form: :14:1: caught exception in inliner for # - java.lang.RuntimeException: no such class: com.gordonlu.device.Device gnu.bytecode.ObjectType.getReflectClass(ObjectType.java:179) gnu.bytecode.ClassType.getModifiers(ClassType.java:103) gnu.bytecode.ClassType.isInterface(ClassType.java:471) gnu.expr.InlineCalls.checkType(InlineCalls.java:56) gnu.expr.InlineCalls.visit(InlineCalls.java:49) gnu.expr.InlineCalls.visitSetExpValue(InlineCalls.java:363) gnu.expr.InlineCalls.visitSetExpValue(InlineCalls.java:28) gnu.expr.ExpVisitor.visitSetExp(ExpVisitor.java:114) gnu.expr.InlineCalls.visitSetExp(InlineCalls.java:369) gnu.expr.InlineCalls.visitSetExp(InlineCalls.java:28) gnu.expr.SetExp.visit(SetExp.java:406) gnu.expr.ExpVisitor.visit(ExpVisitor.java:55) gnu.expr.InlineCalls.visit(InlineCalls.java:46) gnu.expr.InlineCalls.visitBeginExp(InlineCalls.java:272) gnu.expr.InlineCalls.visitBeginExp(InlineCalls.java:28) gnu.expr.BeginExp.visit(BeginExp.java:156) gnu.expr.ExpVisitor.visit(ExpVisitor.java:51) gnu.expr.InlineCalls.visit(InlineCalls.java:46) gnu.expr.InlineCalls.visitBeginExp(InlineCalls.java:272) gnu.expr.InlineCalls.visitBeginExp(InlineCalls.java:28) gnu.expr.BeginExp.visit(BeginExp.java:156) gnu.expr.ExpVisitor.visit(ExpVisitor.java:51) gnu.expr.InlineCalls.visit(InlineCalls.java:46) gnu.expr.InlineCalls.visitLetExp(InlineCalls.java:317) gnu.expr.InlineCalls.visitLetExp(InlineCalls.java:28) gnu.expr.LetExp.visit(LetExp.java:207) gnu.expr.ExpVisitor.visit(ExpVisitor.java:51) gnu.expr.InlineCalls.visit(InlineCalls.java:46) gnu.expr.InlineCalls.visit(InlineCalls.java:28) gnu.expr.LambdaExp.visitChildrenOnly(LambdaExp.java:1664) gnu.expr.LambdaExp.visitChildren(LambdaExp.java:1651) gnu.expr.InlineCalls.visitScopeExp(InlineCalls.java:279) gnu.expr.InlineCalls.visitLambdaExp(InlineCalls.java:349) gnu.expr.InlineCalls.visitLambdaExp(InlineCalls.java:28) gnu.expr.LambdaExp.visit(LambdaExp.java:1640) gnu.expr.ExpVisitor.visit(ExpVisitor.java:55) gnu.expr.InlineCalls.visit(InlineCalls.java:46) gnu.expr.InlineCalls.visit(InlineCalls.java:28) gnu.expr.ExpVisitor.visitAndUpdate(ExpVisitor.java:161) gnu.expr.ExpVisitor.visitExps(ExpVisitor.java:175) gnu.expr.ApplyExp.visitArgs(ApplyExp.java:415) gnu.kawa.reflect.CompileInvoke.validateApplyInvoke(CompileInvoke.java:23) java.lang.reflect.Method.invokeNative(Native Method) java.lang.reflect.Method.invoke(Method.java:521) gnu.expr.InlineCalls.maybeInline(InlineCalls.java:467) gnu.expr.QuoteExp.validateApply(QuoteExp.java:150) gnu.expr.ReferenceExp.validateApply(ReferenceExp.java:191) gnu.kawa.functions.CompilationHelpers.validateApplyToArgs(CompilationHelpers.java:66) java.lang.reflect.Method.invokeNative(Native Method) java.lang.reflect.Method.invoke(Method.java:521) gnu.expr.InlineCalls.maybeInline(InlineCalls.java:467) gnu.expr.QuoteExp.validateApply(QuoteExp.java:150) gnu.expr.ReferenceExp.validateApply(ReferenceExp.java:191) gnu.expr.InlineCalls.visitApplyExp(InlineCalls.java:119) gnu.expr.InlineCalls.visitApplyExp(InlineCalls.java:28) gnu.expr.ApplyExp.visit(ApplyExp.java:410) gnu.expr.ExpVisitor.visit(ExpVisitor.java:55) gnu.expr.InlineCalls.visit(InlineCalls.java:46) gnu.expr.QuoteExp.validateApply(QuoteExp.java:162) gnu.expr.ReferenceExp.validateApply(ReferenceExp.java:191) gnu.kawa.functions.CompilationHelpers.validateApplyToArgs(CompilationHelpers.java:66) java.lang.reflect.Method.invokeNative(Native Method) java.lang.reflect.Method.invoke(Method.java:521) gnu.expr.InlineCalls.maybeInline(InlineCalls.java:467) gnu.expr.QuoteExp.validateApply(QuoteExp.java:150) gnu.expr.ReferenceExp.validateApply(ReferenceExp.java:191) gnu.expr.InlineCalls.visitApplyExp(InlineCalls.java:119) gnu.expr.InlineCalls.visitApplyExp(InlineCalls.java:28) gnu.expr.ApplyExp.visit(ApplyExp.java:410) gnu.expr.ExpVisitor.visit(ExpVisitor.java:51) gnu.expr.InlineCalls.visit(InlineCalls.java:46) gnu.expr.InlineCalls.visitBeginExp(InlineCalls.java:272) gnu.expr.InlineCalls.visitBeginExp(InlineCalls.java:28) gnu.expr.BeginExp.visit(BeginExp.java:156) gnu.expr.ExpVisitor.visit(ExpVisitor.java:51) gnu.expr.InlineCalls.visit(InlineCalls.java:46) gnu.expr.InlineCalls.visit(InlineCalls.java:28) gnu.expr.LambdaExp.visitChildrenOnly(LambdaExp.java:1664) gnu.expr.LambdaExp.visitChildren(LambdaExp.java:1651) gnu.expr.InlineCalls.visitScopeExp(InlineCalls.java:279) gnu.expr.InlineCalls.visitLambdaExp(InlineCalls.java:349) gnu.expr.InlineCalls.visitLambdaExp(InlineCalls.java:28) gnu.expr.ExpVisitor.visitModuleExp(ExpVisitor.java:103) gnu.expr.ModuleExp.visit(ModuleExp.java:482) gnu.expr.ExpVisitor.visit(ExpVisitor.java:51) gnu.expr.InlineCalls.visit(InlineCalls.java:46) gnu.expr.InlineCalls.inlineCalls(InlineCalls.java:33) gnu.expr.Compilation.walkModule(Compilation.java:994) gnu.expr.Compilation.process(Compilation.java:1965) gnu.expr.ModuleInfo.loadByStages(ModuleInfo.java:330) gnu.expr.ModuleExp.evalModule1(ModuleExp.java:238) gnu.expr.ModuleExp.evalModule(ModuleExp.java:198) gnu.expr.Language.eval(Language.java:943) gnu.expr.Language.eval(Language.java:883) gnu.expr.Language.eval(Language.java:865) com.google.appinventor.components.runtime.util.AppInvHTTPD.serve(AppInvHTTPD.java:190) com.google.appinventor.components.runtime.util.NanoHTTPD$HTTPSession.run(NanoHTTPD.java:489) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561) java.lang.Thread.run(Thread.java:1096)
Maybe the emulator doesn't support this feature...?
It's because the emulator is very old I guess. It is just like it was last updated 9-10 years ago... Android is too old on it. Android has very updated now so it supports on the latest new android os!
Nice extension
That extension is so crazy - probably the extension developer put a lot of effort in it.
Version 6 Added!
I would like to thank @Taifun a lot for this update, they let me learn a lot from their extension!
Implemented from Battery Utilities from Kodular.
New blocks:
Method blocks
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: int
BatteryTechnology
Returns the battery technology.
Returns: int
BatteryVoltage
Returns the current battery voltage.
Returns: int
IsBatteryPresent
Indicating whether a battery is present.
Returns: boolean
Property Blocks
BatteryCharging
Returns true if the device is charging, else false.
Returns: boolean
BatteryPlugged
Returns the device the phone is plugged to. Can be 'USB', 'AC', 'WIRELESS' or 'UNKNOWN'.
Returns: text
NOTE: Remember to distinguish the above blocks. They are 100% different.
Launching next version tomorrow or later, probably after my math test.
This is what it is going to be:
BTW: Have you voted yet for OS? Today is the last day!
https://community.appinventor.mit.edu/t/free-get-device-info/48411/18?u=gordon_lu
Voting poll closed. If you want to know some part of the code, PM me.
Hi everyone,
I finally have some time after my test, so I'm introducing version 7. I implemented some more blocks from the Kodular components of Device Utilities, Battery Utilities and Color Utilities, and even some of my own.
Methods
BatteryPluggedSource
Returns the device the phone is plugged to. Can be 'USB', 'AC', 'WIRELESS' or 'UNKNOWN'.
Returns: text
Removed the old property block of BatteryPlugged
.
BatteryStatus
Returns the current status of the phone's battery. Can be:
UNKNOWN
,CHARGING
,DISCHARGING
,NOT_CHARGING
orFULL
.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: 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: int
Parameters:
intColor
= number (int)
DisplayCountry
Returns a name for the locale's country that is appropriate for display to the user.
Returns: string
DisplayLanguage
Returns a name for the locale's language that is appropriate for display to the user.
Returns: text
DisplayScript
Returns a name for the the locale's script that is appropriate for display to the user.
Returns: text
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)
NumberToString
Converts a number to a string.
Returns: text
Parameters:
number
= number (int)
StringToNumber
Converts a string to a number.
Returns: number (int)
Parameters:
string
= text
Property
CpuTemperature
Returns the CPU temperature of the device.
*Returns: number (float)
This is an Open Source property.
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;
}
}
Feel free to copy the code and add it to your extension!
- What do these have to do with device information?
NumberToString
andStringToNumber
can be easily done with app inventor blocks:
The ColorConvertHexToInt
and ColorConvertIntToHex
are in the Kodular documentation, so I was planning to implement them in my extension. They have something to do with that - they are utility blocks, else Kodular won't add them.
There is a way to convert numbers or strings, though.
I have made a library for getting device informations some months ago for my android studio application and is open-source here. You can look over to these codes and add some more too :))
Congratulations for the extension
Version 8!
Big thanks to @oseamiya for this version, I can't create this update without your code.
Methods
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.
DisplayFontScale
Returns the font scale of the display.
Returns: number (float)
DisplayHeight
Returns the display height of the device.
Returns: number (int)
DisplayPhysicalSize
Returns the physical size of the device.
Returns: number (double)
DisplayWidth
Returns the display width of the device.
Returns: number (int)
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
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
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
IsExternalMemoryAvailable
Checks if external memory is available.
Returns: boolean
IsFlashAvailable
Returns true if the device has a flashlight, else false.
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
MemoryFree
Returns the available RAM on the device in Megabytes.
Returns: number (long)
MemoryTotal
Returns the total RAM on the device in Megabytes.
Returns: number (long)
MemoryUsed
Returns the used RAM on the device in Megabytes.
Returns: number (long)
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)
Properties
AndroidVersion
Returns the Android version of the phone.
Returns: string