我正在尝试将呼叫记录器放在其中一切正常工作我也收到音频文件但是当我试着听它时我无法在这里发声我的代码朋友请帮助我我无法理解错误。
Broadcastreceiver.java
public class PhoneStateReceiver extends BroadcastReceiver {
MediaRecorder startrecording;
boolean recordstarted = false;
@Override
public void onReceive(Context context, Intent intent) {
startrecording = new MediaRecorder();
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
Toast.makeText(context, "Incoming call", Toast.LENGTH_SHORT).show();
}
if (state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
Toast.makeText(context, "Received", Toast.LENGTH_SHORT).show();
startrecording.reset();
startrecording.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
startrecording.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
startrecording.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
startrecording.setOutputFile("/sdcard/sample.3gp");
startrecording.setOnErrorListener(new MediaRecorder.OnErrorListener() {
@Override
public void onError(MediaRecorder mediaRecorder, int i, int i1) {
Log.d("Error",mediaRecorder.toString()+" "+String.valueOf(i)+" "+String.valueOf(i1));
}
});
startrecording.setOnInfoListener(new MediaRecorder.OnInfoListener() {
@Override
public void onInfo(MediaRecorder mediaRecorder, int i, int i1) {
Log.d("info",mediaRecorder.toString()+" "+String.valueOf(i)+" "+String.valueOf(i1));
}
});
try {
startrecording.prepare();
startrecording.start();
recordstarted = true;
Toast.makeText(context, "Recording Started", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
}
}
if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
Toast.makeText(context, "Idle", Toast.LENGTH_SHORT).show();
if (recordstarted) {
startrecording = new MediaRecorder();
startrecording.stop();
startrecording.reset();
startrecording.release();
recordstarted = false;
}
}
}
}
的Manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.prominere.prominere.incomingcall">
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.STORAGE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".PhoneStateReceiver">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
</application>
</manifest>