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.
Hello! I just want to Use a share sheet to give more app options to share a specific text. ex: whatsapp, Hangouts, Google+, Facebook, and others apps that are installed in mobile phone whose support sharing!
Thank you in advance!
CurtirCurtir
Ok. happy for help you!
Where do you live my friend?
If you need more help, let me know.
Hugs!
CurtirCurtir
Hello! I live in Brazil.
My situation is: i am learning that Action ShareSheetAction allow to share a specific text via few mobile apps/services, like bluetooth, email, gmail.
But, as my testing smartphone has a lot of text communication apps like whatsapp, facebook, hangouts, i would like to know how to make the share sheet action to make these others app/services appear.
I appreciate your answer!
CurtirCurtir