在 Delphi 11.3 中,您可以使用 Android Intents 来接收其他程序发送的共享文件。以下是实现此功能的步骤:

  1. 在您的 Android 项目中添加一个 TAndroidIntent 组件。

  2. 在 TAndroidIntent 组件的 Properties 中设置以下属性:

  • Action: android.intent.action.SEND

  • DataType: /

  • Categories: [android.intent.category.DEFAULT, android.intent.category.BROWSABLE]

  • Flags: [if_multi_process, if_allow_task_reparenting, if_return_result]

  1. 在 TAndroidIntent 组件的 Events 中添加 OnActivityResult 事件。

  2. 在 OnActivityResult 事件中添加以下代码以处理共享文件:

procedure TForm1.AndroidIntent1ActivityResult(Sender: TObject; const requestCode, resultCode: Integer; const data: JIntent); var fileList: JArrayList; fileUri: Jnet_Uri; file: JFile; begin if resultCode = TJActivity.JavaClass.RESULT_OK then begin fileList := TJArrayList.Wrap((data.getExtras.get(Intent.EXTRA_STREAM) as JParcelableArray)[0]); if fileList <> nil then begin fileUri := TJnet_Uri.Wrap(fileList.get(0)); file := TJFile.JavaClass.init(StringToJString(fileUri.getPath)); // 处理文件 end; end; end;

在这个事件中,我们可以从 intent 数据中获取共享文件的 Uri,然后通过 Uri 获取文件并进行处理。

请注意,由于 Android 中的权限限制,您需要在 AndroidManifest.xml 中声明以下权限:

  • READ_EXTERNAL_STORAGE:允许访问共享文件。

  • WRITE_EXTERNAL_STORAGE:允许写入共享文件。

以上是在 Delphi 11.3 中接收其他程序发送的共享文件的基本步骤,您可以根据您的实际需求进行修改和扩展


原文地址: http://www.cveoy.top/t/topic/fecZ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录