通话记录中的Andr​​oid 2.2 [英] Record Call in Android 2.2

查看:193
本文介绍了通话记录中的Andr​​oid 2.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了这个code录制通话。它工作正常,在Android 2.1系统。在Android 2.2系统,它会创建0字节的输出文件。

I have written this code for recording Calls. It works fine in Android 2.1. In Android 2.2, it creates an output file with 0 bytes.

我怎样才能解决这个问题?

How I can solve this?

MediaRecorder _recorder = new MediaRecorder();


public void start() throws IOException {
    try {
        String state = android.os.Environment.getExternalStorageState();
        if (!state.equals(android.os.Environment.MEDIA_MOUNTED)) {
            throw new IOException("SD Card is not mounted.  It is " + state
                    + ".");
        }

        // make sure the directory we plan to store the recording in exists
        File directory = new File(Environment.getExternalStorageDirectory().getAbsolutePath()
                + "/sam.wav").getParentFile();
        if (!directory.exists() && !directory.mkdirs()) {
            throw new IOException("Path to file could not be created.");
        }


        _recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL );
        _recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
        _recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
        setOutputFile(Environment.getExternalStorageDirectory().getAbsolutePath()
                + "/test.wav");
        _recorder.prepare();
        _recorder.start();

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

推荐答案

使用这段代码

Use this snippet

而不是

_recorder.setAudioSource(android.media.MediaRecorder.AudioSource.VOICE_CALL);

这篇关于通话记录中的Andr​​oid 2.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆