opening the image with the external gallery using delphi

邮差的信 提交于 2019-12-19 10:47:48

问题


I have created Android app using Delphi 10 Seattle. I have stored the image path and from there I need to open the image in the native Android Gallery. How can I implement this functionality?


回答1:


The Java equivalent of what you're trying to do, looks like this (based on open-an-image-using-uri-in-androids-default-gallery-image-viwer)

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://" + "/sdcard/test.jpg"), "image/*");
startActivity(intent);

So if we translate that to Delphi using sending-android-intents-from-delphi-part-2 as a guide, we should get code that looks something like this:

var
  Data: Jnet_Uri;
  Intent: JIntent;
begin
  Intent := TJIntent.Create;
  Intent.setAction(TJIntent.JavaClass.ACTION_VIEW);
  Data := TJnet_Uri.JavaClass.parse(StringToJString('file://' + '/sdcard/test.jpg'));
  Intent.setDataAndType(Data, StringToJString('image/*'));
  SharedActivity.startActivity(Intent);
end;

Of course it's preferable to use

System.IOUtils.TPath.Combine(Path, Filename) in place of the '/sdcard/test.jpg' part of the example code above.



来源:https://stackoverflow.com/questions/34558016/opening-the-image-with-the-external-gallery-using-delphi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!