【问题标题】:Get Recorded file from SDCard and attach it to email client从 SDCard 获取录制文件并将其附加到电子邮件客户端
【发布时间】:2014-01-05 04:45:55
【问题描述】:

我已经在我的应用程序中实现了录音机功能。现在我需要获取文件并将其附加到 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();
    }

}

请任何人帮助我!

【问题讨论】:

  • 那么你的附加文件代码在哪里,你有什么错误还是什么???
  • 不,我什至没有尝试过。我不知道如何获取用于记录的文件
  • 如果我没看错,那么你在 SDCard 中的音频录制文件很强吗???
  • test.pcm 是你的文件.. 使用 file.getAbsolutepath() 获取它的绝对路径,然后使用它
  • @Jolly,试试我下面的答案,告诉我它是否有效。

标签: android file audio path


【解决方案1】:

使用以下代码发送电子邮件...只需在 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);

【讨论】:

  • 我想使用 Gmail Sender 而不是 Intent 来附加文件。现在我的问题是无法获取记录的文件路径。我从哪里获得该路径?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-01
  • 1970-01-01
  • 2011-07-28
  • 2011-12-04
相关资源
最近更新 更多