Android Programming

This is an old revision of Android Programming, edited by Sekelsenmat at . The current revision is 70905.

Go back to Android Interface

Knowing general Android programming can be very useful to help developing the Lazarus Android Interface.

How to...

Read the screen metrics

<delphi> uses androidutil;

var

 MyDisplayMetrics: TDisplayMetrics;
 Str: string;
 //
 lHeight, lWidth: Integer;
 xdpi, ydpi, lScreenSize: Single;

begin

 // ..
 // Objects
 MyDisplayMetrics := TDisplayMetrics.Create;
 Activity.getWindowManager().getDefaultDisplay().getMetrics(MyDisplayMetrics);
 // UI
 lHeight := MyDisplayMetrics.heightPixels();
 lWidth := MyDisplayMetrics.widthPixels();
 xdpi := MyDisplayMetrics.xdpi();
 ydpi := MyDisplayMetrics.ydpi();
 lScreenSize := sqrt(sqr(lHeight / ydpi) + sqr(lWidth / xdpi));
 label_systeminfo := TTextView.Create;
 Str := 'density: ' + FloatToStr(MyDisplayMetrics.density()) + LineEnding;
 Str := Str + 'densityDpi: ' + IntToStr(MyDisplayMetrics.densityDpi()) + LineEnding;
 Str := Str + 'heightPixels: ' + IntToStr(lHeight) + LineEnding;
 Str := Str + 'scaledDensity: ' + FloatToStr(MyDisplayMetrics.scaledDensity()) + LineEnding;
 Str := Str + 'widthPixels: ' + IntToStr(lWidth) + LineEnding;
 Str := Str + 'xdpi: ' + FloatToStr(xdpi) + LineEnding;
 Str := Str + 'ydpi: ' + FloatToStr(ydpi) + LineEnding;
 Str := Str + LineEnding;
 Str := Str + 'Screen Size (Inches): ' + FloatToStr(lScreenSize);
 label_systeminfo.setText(Str);
 layout.addView(label_systeminfo);

</delphi>

Details about Android devices

Since there are so many Android devices, it can be useful to keep track of some information about them. See also in the wikipedia Comparison of Android Devices http://en.wikipedia.org/wiki/Comparison_of_Android_devices and details about the processors in https://wiki.mozilla.org/Mobile/Platforms/Android#System_Requirements.

Smartphones

Manufacturer Model Android API Name (Build.Model) Processor Android version Multi-touch Comments
HTC Wildfire HTC Wildfire armv5 2.1=>2.2 Yes -
Sony Erricson Xperia X10 X10i armv7 1.6=>2.1 No -

Tablets

Manufacturer Model Android API Name (Build.Model) Processor Android version Multi-touch Comments
Toshiba Folio 100 Tablet TOSHIBA_FOLIO_AND_A armv7 2.2 Yes -

List of devices ordered by processor compatibility (ARMv5/6 vs ARMv7)

List of ARMv7 devices:

List of ARMv5 or ARMv6 processors:

Creating a new Java Android Application

Generic instructions here: http://developer.android.com/guide/developing/other-ide.html

References