gpt4 book ai didi

android - 从SDCard获取记录的文件并将其附加到电子邮件客户端

转载 作者:行者123 更新时间:2023-12-03 02:15:07 27 4
gpt4 key购买 nike

我已经在应用程序中实现了录音机功能,现在我需要获取文件并将其附加到GMailSender,如何获取文件,这是我尝试启动视频的代码,UI中有一个保存按钮,当它被单击时,音频文件将自动附加到邮件中。

private void startRecord()
{
File file = new File(Environment.getExternalStorageDirectory(), "test.pcm");
try
{
file.createNewFile();
OutputStream outputStream = new FileOutputStream(file);
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream);
DataOutputStream dataOutputStream = new DataOutputStream(bufferedOutputStream);

int minBufferSize = AudioRecord.getMinBufferSize(8000,
AudioFormat.CHANNEL_IN_MONO,
AudioFormat.ENCODING_PCM_16BIT);

short[] audioData = new short[minBufferSize];

AudioRecord audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC, 8000,
AudioFormat.CHANNEL_IN_MONO,
AudioFormat.ENCODING_PCM_16BIT,
minBufferSize);

audioRecord.startRecording();

while(recording)
{
int numberOfShort = audioRecord.read(audioData, 0, minBufferSize);
for(int i = 0; i < numberOfShort; i++)
{
dataOutputStream.writeShort(audioData[i]);
}
}
audioRecord.stop();
audioRecord.release();
dataOutputStream.close();

}
catch (IOException e)
{
e.printStackTrace();
}

}

请任何人帮助我!

最佳答案

使用下面的代码发送电子邮件...只需在onCreate方法中使用此代码,即可完成发送邮件。

   String subject = "Your subject name";
String message = "Message "

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("audio/*");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {
"email-id"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
Uri uri = Uri.fromFile(new File(Environment
.getExternalStorageDirectory(), "path of audio file"));
emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
emailIntent.setType("text/plain");
startActivity(emailIntent);

关于android - 从SDCard获取记录的文件并将其附加到电子邮件客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20633872/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com