Skip to content

Instantly share code, notes, and snippets.

@DelphiWorlds
DelphiWorlds / SendCancelNotificationFix.pas
Created June 7, 2022 08:16
A fix for the banner not showing for the SendCancelNotification demo for Delphi 11
// Original demo is at:
// https://github.com/Embarcadero/RADStudio11Demos/tree/main/Object%20Pascal/Mobile%20Snippets/Notifications/SendCancelNotification
// Code to add to the implementation section. Use code completion to add it to the interface section:
const
cNotificationChannelId = 'NotificationsDemo';
constructor TNotificationsForm.Create(AOwner: TComponent);
begin
@DelphiWorlds
DelphiWorlds / FeedDateToDateTime.pas
Last active December 25, 2021 00:46
Convert an RSS/Atom date to datetime
uses
System.SysUtils, System.DateUtils, System.StrUtils;
// examples:
// Wed, 3 Nov 2021 18:20:21 +1030
// 21 Dec 2021 19:04:06 GMT
function FeedDateToDateTime(const AFeedDate: string): TDateTime;
var
LParts: TArray<string>;
LISO8601, LDay, LMonth: string;
@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;