要在 Delphi 11.3 中注册接收共享文件,可以按照以下步骤操作:

  1. 在你的 Android 项目中添加一个 TApplicationEvent 组件。

  2. 在 TApplicationEvent 组件的 OnNewIntent 事件中添加以下代码:

if ANewIntent.Intent.Action = TJIntent.JavaClass.ACTION_SEND then
begin
  if ANewIntent.Intent.Type = 'text/plain' then
  begin
    //处理文本共享文件
    Memo1.Lines.Add(ANewIntent.Intent.Extras.
      GetString(TJIntent.JavaClass.EXTRA_TEXT));
  end
  else if ANewIntent.Intent.Type.startsWith('image/') then
  begin
    //处理图像共享文件
    ImageView1.Bitmap.LoadFromStream(ANewIntent.Intent.
      GetParcelableExtra(TJIntent.JavaClass.EXTRA_STREAM)
      as JInputStream);
  end;
end;
  1. 在 AndroidManifest.xml 文件中添加以下代码:
<intent-filter>
  <action android:name="android.intent.action.SEND" />
  <category android:name="android.intent.category.DEFAULT" />
  <data android:mimeType="*/*" />
</intent-filter>

这样,你的应用程序就可以接收来自其他应用程序的共享文件了。你可以在 OnNewIntent 事件中处理这些文件,例如将文本显示在 Memo 组件中,将图像显示在 ImageView 组件中,等等。

Delphi 11.3 Android 10 应用接收共享文件教程

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

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