Skip to content

Instantly share code, notes, and snippets.

@DelphiWorlds
DelphiWorlds / ExtractEXIFAndroid.pas
Created June 23, 2020 02:11
Extracting EXIF data on Android
uses
Androidapi.JNI.Media, Androidapi.JNIBridge;
var
LEXIF: JExifInterface;
LLatLong: TJavaArray<Single>;
LOrientation: Integer;
LLatitude, LLongitude: Single;
LDateTaken, LCameraMake, LCameraModel: string;
begin
uses
Androidapi.JNI.WebKit;
procedure TForm1.Button1Click(Sender: TObject);
var
LWebView: JWebView;
begin
if Supports(WebBrowser1, JWebView, LWebView) then
LWebView.clearHistory;
end;
uses
Androidapi.JNI.App, Androidapi.Helpers, Androidapi.JNI.GraphicsContentViewText;
// Available memory in MB
function GetMemory: Int64;
var
LMemoryInfo: JActivityManager_MemoryInfo;
LActivityManager: JActivityManager;
begin
LActivityManager := TJActivityManager.Wrap(JObjectToID(TAndroidHelper.Context.getSystemService(TJActivity.JavaClass.ACTIVITY_SERVICE)));
uses
System.Permissions;
procedure TForm1.RequestCallPhonePermission;
begin
PermissionsService.RequestPermissions(['android.permission.CALL_PHONE'],
procedure(const APermissions: TArray<string>; const AGrantResults: TArray<TPermissionStatus>)
begin
if AGrantResults[0] = TPermissionStatus.Granted then
// Permission has been granted
@DelphiWorlds
DelphiWorlds / FormHelperInterface.pas
Created January 21, 2020 22:28
Implementing an interface via a helper
unit Unit1;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Controls.Presentation, FMX.StdCtrls;
type
ITest = interface(IInterface)
uses
Androidapi.JNI.GraphicsContentViewText, Androidapi.JNI.Os, Androidapi.JNI.JavaTypes, Androidapi.Helpers;
procedure SendBroadcast(const AIntent: JIntent);
var
LResolveInfoList: JList;
LResolveInfo: JResolveInfo;
LComponentName: JComponentName;
LExplicitIntent: JIntent;
I: Integer;
@DelphiWorlds
DelphiWorlds / AddingStrings.pas
Last active October 20, 2019 08:21
StringList value type alternative
type
StringList = TArray<string>;
StringListHelper = record helper for StringList
public
procedure Add(const AValue: string);
end;
{ StringListHelper }
@DelphiWorlds
DelphiWorlds / EnumNetPrinters.pas
Last active January 21, 2019 03:40
Enumerating network printers in Windows
type
TNetResourceArray = TArray<TNetResource>;
function EnumerateContainedPrinters(const AContainer: TNetResource): TNetResourceArray;
var
LResult, LBufferSize: DWORD;
LEnumHandle: THandle;
LNetResources: TNetResourceArray;
I: Integer;
LEntries : Longint;
@DelphiWorlds
DelphiWorlds / FrameworkInputPaneHandler.pas
Last active January 21, 2019 03:42
Work in progress to handle when the Windows 10 OSK shows/hides
unit FrameworkInputPaneHandler;
interface
uses
System.Win.ComObj,
Winapi.Windows;
// https://github.com/tpn/winsdk-10/blob/master/Include/10.0.10240.0/um/ShObjIdl.idl
const
@DelphiWorlds
DelphiWorlds / TryFinallySafety.pas
Created February 6, 2018 23:03
Distinction between causing and raising an exception, and try..finally safety
type
TSomeObject = class(TObject)
public
procedure DoSomething;
end;
TFaultyObject = class(TObject)
private
FStrings: TStrings;
public