I recently got a question on my blog on how to use the ShareSheet implementation on iOS and Android in code instead of using the built-in actions.
Using the built-in ShareSheet action, it only takes one line of code to share an image (or text) in your FireMonkey mobile app.
Here is a simple example using actions. You can download the code snippet here.
procedure TShareSheetForm.ShowShareSheetAction1BeforeExecute(Sender: TObject);
begin
{ show the share sheet }
ShowShareSheetAction1.Bitmap.Assign(imgCameraPicture.Bitmap);
end;
Here is how you can use ShareSheet to share images or text in your application without using the built-in actions:
unit MainFrm;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls, FMX.Layouts, FMX.Objects, FMX.Edit;type
TForm1 = class(TForm)
Edit1: TEdit;
Image1: TImage;
SwitchSendText: TSwitch;
SwitchSendImage: TSwitch;
Button1: TButton;
Layout1: TLayout;
Layout2: TLayout;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation
uses
FMX.Platform, FMX.MediaLibrary;{$R *.fmx}
procedure TForm1.Button1Click(Sender: TObject);
var
ShareSheetService: IFMXShareSheetActionsService;
SharedText: string;
SharedImage: TBitmap;
begin
if TPlatformServices.Current.SupportsPlatformService(IFMXShareSheetActionsService, IInterface(ShareSheetService)) then
begin
if SwitchSendText.IsChecked then
SharedText := Edit1.Text
else
SharedText := ‘ ‘;if SwitchSendImage.IsChecked then
SharedImage := Image1.Bitmap
else
SharedImage := nil;{ Share Data}
ShareSheetService.Share(Button1, SharedText, SharedImage);
end;
end;end.
//Sarina