从SDCard获取记录的文件并将其附加到电子邮件客户端
我在我的应用程序中实现了音频记录器功能。现在我需要获取该文件并将其附加到GMailSender。如何获取文件。这是代码我尝试启动视频。在我的用户界面中有一个保存按钮,当它被点击时,音频文件将自动附加到邮件。从SDCard获取记录的文件并将其附加到电子邮件客户端
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);
以上是 从SDCard获取记录的文件并将其附加到电子邮件客户端 的全部内容, 来源链接: utcz.com/qa/265854.html