|
@@ -3,6 +3,7 @@ unit Unit1;
|
|
interface
|
|
interface
|
|
|
|
|
|
uses
|
|
uses
|
|
|
|
+ System.Messaging,
|
|
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
|
|
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
|
|
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
|
|
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
|
|
FMX.Controls.Presentation, FMX.ScrollBox, FMX.Memo;
|
|
FMX.Controls.Presentation, FMX.ScrollBox, FMX.Memo;
|
|
@@ -12,12 +13,18 @@ type
|
|
mmo1: TMemo;
|
|
mmo1: TMemo;
|
|
btn1: TButton;
|
|
btn1: TButton;
|
|
btn2: TButton;
|
|
btn2: TButton;
|
|
- Button1: TButton;
|
|
|
|
|
|
+ btn3: TButton;
|
|
|
|
+ btn4: TButton;
|
|
procedure btn2Click(Sender: TObject);
|
|
procedure btn2Click(Sender: TObject);
|
|
procedure btn1Click(Sender: TObject);
|
|
procedure btn1Click(Sender: TObject);
|
|
- procedure Button1Click(Sender: TObject);
|
|
|
|
|
|
+ procedure btn3Click(Sender: TObject);
|
|
|
|
+ procedure btn4Click(Sender: TObject);
|
|
|
|
+ procedure FormCreate(Sender: TObject);
|
|
|
|
+ procedure FormDestroy(Sender: TObject);
|
|
private
|
|
private
|
|
{ Private declarations }
|
|
{ Private declarations }
|
|
|
|
+ procedure DoReceivedImagePath(const Sender: TObject; const M: TMessage);
|
|
|
|
+ procedure DoCancelReceivingImage(const Sender: TObject; const M: TMessage);
|
|
public
|
|
public
|
|
{ Public declarations }
|
|
{ Public declarations }
|
|
end;
|
|
end;
|
|
@@ -31,11 +38,12 @@ implementation
|
|
|
|
|
|
uses
|
|
uses
|
|
{$IFDEF ANDROID}
|
|
{$IFDEF ANDROID}
|
|
- Androidapi.JNI.GraphicsContentViewText,
|
|
|
|
|
|
+ Androidapi.JNI.GraphicsContentViewText, Androidapi.JNI.Provider,
|
|
Androidapi.JNI.JavaTypes, Androidapi.JNI.App, Androidapi.JNI.Net,
|
|
Androidapi.JNI.JavaTypes, Androidapi.JNI.App, Androidapi.JNI.Net,
|
|
Androidapi.Helpers, ksAndroid.Helpers,
|
|
Androidapi.Helpers, ksAndroid.Helpers,
|
|
|
|
+ FMX.Platform.Android,
|
|
{$ENDIF}
|
|
{$ENDIF}
|
|
- System.Messaging;
|
|
|
|
|
|
+ FMX.Platform;
|
|
|
|
|
|
type
|
|
type
|
|
TOpenFileCallback = reference to procedure(const ACode: Integer; const APath: string);
|
|
TOpenFileCallback = reference to procedure(const ACode: Integer; const APath: string);
|
|
@@ -125,14 +133,14 @@ begin
|
|
LIntent := TJIntent.JavaClass.init(FAction);
|
|
LIntent := TJIntent.JavaClass.init(FAction);
|
|
LIntent.setType(StringToJString(LType));
|
|
LIntent.setType(StringToJString(LType));
|
|
//Intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); 多选
|
|
//Intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); 多选
|
|
- if FAction.equals(TJIntent.JavaClass.ACTION_PICK) then
|
|
|
|
- //Intent.setData(TJImages_Media.JavaClass.EXTERNAL_CONTENT_URI) // 这个可以用来限定APP,比如这个就是 图库
|
|
|
|
- //Intent.setData(TJContactsContract_Contacts.JavaClass.CONTENT_URI) // 联系人,不指定这个的话会直接取消
|
|
|
|
- else begin
|
|
|
|
|
|
+
|
|
|
|
+ if not FAction.equals(TJIntent.JavaClass.ACTION_PICK) then
|
|
LIntent.addCategory(TJIntent.JavaClass.CATEGORY_OPENABLE);
|
|
LIntent.addCategory(TJIntent.JavaClass.CATEGORY_OPENABLE);
|
|
- if ADir <> '' then
|
|
|
|
- LIntent.setData(TAndroidHelperEx.UriParse(ADir));
|
|
|
|
- end;
|
|
|
|
|
|
+
|
|
|
|
+ if AData <> nil then
|
|
|
|
+ LIntent.setData(AData)
|
|
|
|
+ else if ADir <> '' then
|
|
|
|
+ LIntent.setData(TAndroidHelperEx.UriParse(ADir));
|
|
|
|
|
|
if FMessageChooserID = 0 then begin
|
|
if FMessageChooserID = 0 then begin
|
|
FMessageChooserID := TMessageManager.DefaultManager.SubscribeToMessage(TMessageResultNotification, HandleActivityMessage);
|
|
FMessageChooserID := TMessageManager.DefaultManager.SubscribeToMessage(TMessageResultNotification, HandleActivityMessage);
|
|
@@ -141,17 +149,23 @@ begin
|
|
end;
|
|
end;
|
|
|
|
|
|
try
|
|
try
|
|
- //Result := TAndroidHelperEx.StartActivity(TJIntent.JavaClass.createChooser(Intent, StrToJCharSequence(ATitle)), FILE_SELECT_CODE)
|
|
|
|
- Result := TAndroidHelperEx.StartActivity(LIntent, FILE_SELECT_CODE);
|
|
|
|
- except
|
|
|
|
- raise Exception.Create('File Manager not found');
|
|
|
|
|
|
+ try
|
|
|
|
+ //Result := TAndroidHelperEx.StartActivity(TJIntent.JavaClass.createChooser(Intent, StrToJCharSequence(ATitle)), FILE_SELECT_CODE)
|
|
|
|
+ Result := TAndroidHelperEx.StartActivity(LIntent, FILE_SELECT_CODE);
|
|
|
|
+ except
|
|
|
|
+ raise Exception.Create('File Manager not found');
|
|
|
|
+ end;
|
|
|
|
+ finally
|
|
|
|
+ Form1.mmo1.Lines.Add(Format('OpenFileDialog:%s', [BoolToStr(Result, True)]));
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure TForm1.btn1Click(Sender: TObject);
|
|
procedure TForm1.btn1Click(Sender: TObject);
|
|
begin
|
|
begin
|
|
|
|
+ //Intent.setData(TJImages_Media.JavaClass.EXTERNAL_CONTENT_URI) // 这个可以用来限定APP,比如这个就是 图库
|
|
|
|
+ //Intent.setData(TJContactsContract_Contacts.JavaClass.CONTENT_URI) // 联系人,不指定这个的话会直接取消
|
|
FAction := TJIntent.JavaClass.ACTION_PICK;
|
|
FAction := TJIntent.JavaClass.ACTION_PICK;
|
|
- OpenFileDialog('*/*', '', nil,
|
|
|
|
|
|
+ OpenFileDialog('*/*', '', TJImages_Media.JavaClass.EXTERNAL_CONTENT_URI,
|
|
procedure(const ACode: Integer; const APath: string) begin
|
|
procedure(const ACode: Integer; const APath: string) begin
|
|
if APath <> '' then
|
|
if APath <> '' then
|
|
mmo1.Lines.Add(APath)
|
|
mmo1.Lines.Add(APath)
|
|
@@ -174,7 +188,7 @@ begin
|
|
)
|
|
)
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TForm1.Button1Click(Sender: TObject);
|
|
|
|
|
|
+procedure TForm1.btn3Click(Sender: TObject);
|
|
begin
|
|
begin
|
|
FAction := TJIntent.JavaClass.ACTION_OPEN_DOCUMENT;
|
|
FAction := TJIntent.JavaClass.ACTION_OPEN_DOCUMENT;
|
|
OpenFileDialog('*/*', '', nil,
|
|
OpenFileDialog('*/*', '', nil,
|
|
@@ -187,4 +201,37 @@ begin
|
|
)
|
|
)
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+procedure TForm1.btn4Click(Sender: TObject);
|
|
|
|
+var
|
|
|
|
+ FSize: TSize;
|
|
|
|
+begin
|
|
|
|
+ FSize.cx := TCanvasManager.DefaultCanvas.GetAttribute(TCanvasAttribute.MaxBitmapSize);
|
|
|
|
+ FSize.cy := TCanvasManager.DefaultCanvas.GetAttribute(TCanvasAttribute.MaxBitmapSize);
|
|
|
|
+ MainActivity.getFMXMediaLibrary.takeImageFromLibrary(FSize.Width, FSize.Height, False);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TForm1.DoCancelReceivingImage(const Sender: TObject; const M: TMessage);
|
|
|
|
+begin
|
|
|
|
+ if (M is TMessageCancelReceivingImage) then
|
|
|
|
+ mmo1.Lines.Add('TMessageCancelReceivingImage');
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TForm1.DoReceivedImagePath(const Sender: TObject; const M: TMessage);
|
|
|
|
+begin
|
|
|
|
+ if (M is TMessageReceivedImagePath) then
|
|
|
|
+ mmo1.Lines.Add(Format('TMessageReceivedImagePath: %s', [(M as TMessageReceivedImagePath).Value]));
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TForm1.FormCreate(Sender: TObject);
|
|
|
|
+begin
|
|
|
|
+ TMessageManager.DefaultManager.SubscribeToMessage(TMessageCancelReceivingImage, DoCancelReceivingImage);
|
|
|
|
+ TMessageManager.DefaultManager.SubscribeToMessage(TMessageReceivedImagePath, DoReceivedImagePath);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TForm1.FormDestroy(Sender: TObject);
|
|
|
|
+begin
|
|
|
|
+ TMessageManager.DefaultManager.Unsubscribe(TMessageReceivedImagePath, DoReceivedImagePath);
|
|
|
|
+ TMessageManager.DefaultManager.Unsubscribe(TMessageCancelReceivingImage, DoCancelReceivingImage);
|
|
|
|
+end;
|
|
|
|
+
|
|
end.
|
|
end.
|