【问题标题】:Android can't record incoming calls with clear voiceAndroid 无法用清晰的声音记录来电
【发布时间】:2019-05-01 13:09:00
【问题描述】:

我只能用这段代码录下我的声音,而不是反对转弯。

我用MediaRecorder.AudioSource.VOICE_CALL代替MediaRecorder.AudioSource.MIC

但我仍然只能听到自己的声音。

这是我的代码

public class RecorderService extends IntentService {

    private Context mContext;
    private MediaRecorder recorder;
    static final String TAGS = "RecorderService";

    private String phoneNumber;

    public RecorderService() {
        super("RecorderService");
    }

    @Override
    protected void onHandleIntent(Intent intent) {
    }

    @Override
    public int onStartCommand(@Nullable Intent intent, int flags, int startId) {
        Log.e(TAGS, "Started!");
        mContext = getApplicationContext();

        phoneNumber = intent.getStringExtra("number");
        Log.e(TAGS, "Calling Number : " + phoneNumber);

        recorder = new MediaRecorder();
        startRecording();

        return START_NOT_STICKY;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.e(TAGS, "Stopped!");
        stopRecording();
    }

    private void startRecording() {
        Log.e(TAGS, "Recording Started");

        File file = new File(Environment.getExternalStorageDirectory()
                + File.separator
                + "My Records"
                + File.separator);

        recorder.reset();
        recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
        recorder.setOutputFile(file.getAbsolutePath() + "record.mp3");

        try {
            recorder.prepare();
        } catch (IOException e) {
            e.printStackTrace();
        }
        recorder.start();
    }

    private void stopRecording() {
        Log.e(TAGS, "Recording Stopped");
        if (recorder != null) {
            recorder.stop();
            recorder.reset();
            recorder.release();
            recorder = null;
        }
    }
}

任何建议!

【问题讨论】:

标签: android


【解决方案1】:

你不能。除非您是系统应用程序(您需要安装自己的自定义操作系统或以 root 身份获取),否则不会。 VOICE_CALL 需要 CAPTURE_AUDIO_OUTPUT 权限,这是一个系统权限,普通应用无法使用。

Play 商店中的其他应用是如何做到的?他们使用麦克风,希望通话的输出声音足够大,可以接听。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-16
    • 2022-12-21
    • 2019-12-13
    • 2012-09-10
    • 1970-01-01
    • 2023-03-17
    • 2011-10-05
    相关资源
    最近更新 更多