掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
ios/androidでPDFをファイル共有方法について (ID:150774)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
takeさん 返信が遅くなり、またはご説明も悪く、大変申し訳ございませんでした。 DelphiWorldsのKastriという素晴らしいライブラリで解決することができました。 https://github.com/DelphiWorlds/Kastri サンプルソースは上記展開後の下記にあります。 Kastri-master\Demos\ShareItems Unit1のソースを貼り付けておきます。 プログラムを起動し、ボタンをタップするとiOSのシェアシートメニューが表示され、 テンポラリフォルダにあるPDFをメニューに表示されたSlackやAirPrintの印刷処理に渡すことができるようになります。 unit Unit1; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Controls.Presentation, FMX.StdCtrls, DW.ShareItems, FMX.Objects, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP, system.NetEncoding, IdSSLOpenSSL, System.Net.HttpClientComponent; type TForm1 = class(TForm) Button1: TButton; Image1: TImage; Button2: TButton; procedure Button1Click(Sender: TObject); private FExcluded: TShareActivities; FShareItems: TShareItems; procedure Share; procedure ShareItemsShareCompletedHandler(Sender: TObject; const AActivity: TShareActivity; const AError: string); public constructor Create(AOwner: TComponent); override; destructor Destroy; override; end; var Form1: TForm1; implementation {$R *.fmx} uses System.IOUtils, System.Permissions, DW.Consts.Android, DW.Permissions.Helpers; { TForm1 } constructor TForm1.Create(AOwner: TComponent); begin inherited; // Exclude all but the following - Note: applicable to iOS ONLY - uncomment the next line to test // FExcluded := TShareItems.AllShareActivities - [TShareActivity.Message, TShareActivity.Mail, TShareActivity.CopyToPasteboard]; FShareItems := TShareItems.Create; FShareItems.OnShareCompleted := ShareItemsShareCompletedHandler; end; destructor TForm1.Destroy; begin FShareItems.Free; inherited; end; procedure TForm1.ShareItemsShareCompletedHandler(Sender: TObject; const AActivity: TShareActivity; const AError: string); begin // If AActivity is TShareActivity.None, then the user cancelled - except for Android because it does not tell you :-/ if AActivity = TShareActivity.None then ShowMessage('Share cancelled') else ShowMessage('Share completed'); end; procedure TForm1.Button1Click(Sender: TObject); begin PermissionsService.RequestPermissions([cPermissionReadExternalStorage, cPermissionWriteExternalStorage], procedure(const APermissions: TPermissionArray; const AGrantResults: TPermissionStatusArray) begin if AGrantResults.AreAllGranted then Share; end ); end; procedure TForm1.Share; var LSharedFileName: string; begin FShareItems.AddFile(TPath.Combine(TPath.GetTempPath, 'test.pdf')); FShareItems.Share(Button1, FExcluded); end; end.
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.