简体   繁体   English

将文件夹添加到 Android 项目 (Delphi)

[英]Add a folder to an Android project (Delphi)

When making Android apps with Delphi, I know how to use the Deployment Manager to add a file that I can access at runtime.在使用 Delphi 制作 Android 应用程序时,我知道如何使用部署管理器添加我可以在运行时访问的文件。 But I need to add hundreds of files.但我需要添加数百个文件。 Is there a way to add an entire folder instead of just individual files?有没有办法添加整个文件夹而不仅仅是单个文件? Example use case: a language learning app with hundreds of pictures corresponding to vocabulary words.示例用例:一个语言学习应用程序,其中包含与词汇单词相对应的数百张图片。

Here is what worked for me:这对我有用:

  1. Get an aws.amazon.com account and store the data you need in an S3 bucket获取 aws.amazon.com 账户并将您需要的数据存储在 S3 存储桶中

  2. Use the Object Inspector to place an AmazonConnectInfo on your form.使用 Object Inspector 在您的表单上放置一个 AmazonConnectInfo。 Edit the Account Name and Account Key to your aws credentials.将帐户名称和帐户密钥编辑为您的 aws 凭证。 Make sure the 'Region' and 'Endpoints' match the region you selected on aws.amazon.com, ex: "ca-central-1" for the Region and "s3.ca-central-1.amazonaws.com" for the three EndPoints.确保“区域”和“端点”与您在 aws.amazon.com 上选择的区域相匹配,例如:“ca-central-1”用于区域,“s3.ca-central-1.amazonaws.com”用于三个端点。

  3. Use this code to play any audio file from the bucket:使用此代码播放存储桶中的任何音频文件:

    const BUCKET_NAME = 'name of your s3 bucket'; const BUCKET_NAME = '您的 s3 存储桶的名称';

    procedure TForm1.FetchAndPlaySound;程序 TForm1.FetchAndPlaySound; var s3: TAmazonStorageService; var s3:TAmazonStorageService; thefilestream: TFileStream;文件流:TFileStream; NameOfFile: String;文件名:字符串;

    begin开始

    NameOfFile:= 'subfoldername/example.wav'; NameOfFile:= '子文件夹名/example.wav';

    thefilestream:= TFileStream.Create(System.Ioutils.TPath.GetDocumentsPath + PathDelim + 'Dynamite.wav',fmOpenWrite); thefilestream:= TFileStream.Create(System.Ioutils.TPath.GetDocumentsPath + PathDelim + 'Dynamite.wav',fmOpenWrite);

    s3:= TAmazonStorageService.Create(AmazonConnectionInfo1); s3:= TAmazonStorageService.Create(AmazonConnectionInfo1);

    try尝试

    if s3.GetObject(BUCKET_NAME, NameOfFile, thefilestream ) then如果 s3.GetObject(BUCKET_NAME, NameOfFile, thefilestream) 那么

    begin开始

    //Where 'dynamite.wav' is a placeholder file put in the local memory using the Deployment Manager, asset/internal //其中'dynamite.wav'是一个占位符文件,使用部署管理器放置在本地memory中,asset/internal

    MediaPlayer1.FileName:= System.Ioutils.TPath.GetDocumentsPath + PathDelim + 'Dynamite.wav'; MediaPlayer1.FileName:= System.Ioutils.TPath.GetDocumentsPath + PathDelim + 'Dynamite.wav';

    MediaPlayer1.Play;媒体播放器1.播放;

    end结尾

    else别的

    begin开始

    else ShowMessage('missing file: ' + NameOfFile); else ShowMessage('缺少文件:' + NameOfFile);

    end;结尾;

    finally最后

    s3.Free; s3.免费;

    thefilestream.Free;文件流。免费;

    end;结尾;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM