Sharing images and data on mobile

Sharing images and data on mobile

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.

3 opiniões sobre “Sharing images and data on mobile

  1. 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!

    Curtir

      • 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!

        Curtir

Deixe um comentário

Preencha os seus dados abaixo ou clique em um ícone para log in:

Logotipo do WordPress.com

Você está comentando utilizando sua conta WordPress.com. Sair / Alterar )

Imagem do Twitter

Você está comentando utilizando sua conta Twitter. Sair / Alterar )

Foto do Facebook

Você está comentando utilizando sua conta Facebook. Sair / Alterar )

Foto do Google+

Você está comentando utilizando sua conta Google+. Sair / Alterar )

Conectando a %s