Skip to content

Instantly share code, notes, and snippets.

@DelphiWorlds
DelphiWorlds / PendingIntentArrayListExample.pas
Created October 16, 2021 00:46
How to put a PendingIntent into an ArrayList
uses
Androidapi.JNI.JavaTypes, Androidapi.JNI.App, Androidapi.JNI.GraphicsContentViewText, Androidapi.Helpers;
var
LArrayList: JArrayList;
LIntent: JIntent;
LPendingIntent: JPendingIntent
begin
LIntent := TJIntent.Create;
// *** Here, call setAction and whatever else needs to be done to initialize LIntent ***
@DelphiWorlds
DelphiWorlds / BonjourTest.pas
Created September 10, 2021 23:00
Example of how a Bonjour service *might* be set up on macOS. Has not been fully tested
unit Unit1;
// With help from this SO post:
// https://stackoverflow.com/a/16678161/3164070
// ******* NOTE *********
// As per the comment in the Acivate method:
// This assumes you have actually created a socket that is listening on the selected port
interface
@DelphiWorlds
DelphiWorlds / NSNetServiceDelegate.pas
Created September 1, 2021 20:16
Import of NSNetServiceDelegate etc
uses
Macapi.Foundation;
type
NSNetService = interface;
NSNetServiceBrowser = interface;
NSNetServiceDelegate = interface;
NSNetServiceBrowserDelegate = interface;
PNSInputStream = ^NSInputStream;
@DelphiWorlds
DelphiWorlds / MapMarkerExample.pas
Created May 2, 2021 20:08
Create 2 markers, not far from each other
type
TForm1 = class(TForm)
Map: TMapView;
private
FMarkerA: TMapMarker;
FMarkerB: TMapMarker;
procedure AddMarkers;
public
constructor Create(AOwner: TComponent); override;
end;
@DelphiWorlds
DelphiWorlds / ShowManageExternalStorageSettings.pas
Created April 18, 2021 21:26
Code to show the manage external storage permissions settings (Android 11)
uses
Androidapi.Helpers, Androidapi.JNI.Provider, Androidapi.JNI.GraphicsContentViewText;
procedure ShowManageExternalStorageSettings;
var
LIntent: JIntent;
begin
LIntent := TJIntent.Create;
LIntent.setAction(StringToJString('android.settings.MANAGE_ALL_FILES_ACCESS_PERMISSION');
LIntent.setData(TJnet_Uri.JavaClass.parse(StringToJString('package:' + JStringtoString(TAndroidHelper.Context.getPackageName()))));
@DelphiWorlds
DelphiWorlds / TrashFile.pas
Last active March 16, 2021 13:22
Sending a file or directory to the trash on macOS/iOS. NOTE: *** On iOS, works only on iOS 11 or above ***
uses
{$IF Defined(IOS)}
Macapi.ObjectiveC,
iOSapi.Foundation,
{$ELSE}
Macapi.Foundation,
{$ENDIF}
Macapi.Helpers;
{$IF Defined(IOS)}
@DelphiWorlds
DelphiWorlds / FMX.Maps.iOS.Patch.pas
Created January 29, 2021 00:40
Show callout for map marker on iOS
// Note: this is just parts of the unit to show what to "patch". Please refer to the readme.md in this gist
unit FMX.Maps.iOS;
interface
{$SCOPEDENUMS ON}
procedure RegisterMapService;
implementation
@DelphiWorlds
DelphiWorlds / PutBack.pas
Created January 15, 2021 22:41
Put application in background on Android
uses
Androidapi.Helpers;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState);
begin
if key = vkHardwareBack then
begin
Key := 0;
TAndroidHelper.Activity.moveTaskToBack(True);
end;
@DelphiWorlds
DelphiWorlds / MigrationToolQP.md
Created September 6, 2020 22:12
Collection of QP reports related to Migration Tool in RADStudio

https://quality.embarcadero.com/browse/RSP-30432 (Missing Recent and Favorite projects) https://quality.embarcadero.com/browse/RSP-27078 (Missing Closed Projects) https://quality.embarcadero.com/browse/RSP-26695 (UI issue and missing environment vars) https://quality.embarcadero.com/browse/RSP-26796 (Ignores Platform SDK settings) https://quality.embarcadero.com/browse/RSP-25565 (Ignores Search\DirectoryLists) https://quality.embarcadero.com/browse/RSP-23451 (Support migrating when install is in a new path) https://quality.embarcadero.com/browse/RSP-17951 (Missing Environment vars) https://quality.embarcadero.com/browse/RSP-15354 (Migrate desktop settings - Won't fix)

@DelphiWorlds
DelphiWorlds / AndroidCheckDarkMode.pas
Created July 23, 2020 13:46
Check Android for dark mode (untested)
uses
Androidapi.JNI.GraphicsContentViewText, Androidapi.Helpers;
function IsDarkMode: Boolean;
var
LMode: Integer;
begin
LMode := TAndroidHelper.Context.getResources.getConfiguration.uiMode and TJConfiguration.JavaClass.UI_MODE_NIGHT_MASK;
Result := LMode = TJConfiguration.JavaClass.UI_MODE_NIGHT_YES;
end;