Android呼叫录制应用程序,引发异常

Android呼叫录制应用程序,引发异常,android,record,mediarecorder,Android,Record,Mediarecorder,当我在Emulator中运行以下代码时,call启动,当call断开连接时,调用stop函数时显示NullPointerException,当使用VOICE_call作为音频源时,输出为空文件。但是,当我将VOICE_UPLINK作为音频源时(仍然存在空指针异常),它就起作用了。当我在设备中运行它时,它会显示FileNotFound异常,并在拨打号码后立即显示权限被拒绝。但是我已经在清单文件中授予了所需的权限 <uses-permission android:name="android.p

当我在Emulator中运行以下代码时,call启动,当call断开连接时,调用stop函数时显示NullPointerException,当使用VOICE_call作为音频源时,输出为空文件。但是,当我将VOICE_UPLINK作为音频源时(仍然存在空指针异常),它就起作用了。当我在设备中运行它时,它会显示FileNotFound异常,并在拨打号码后立即显示权限被拒绝。但是我已经在清单文件中授予了所需的权限

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />

我做错什么了吗?我听说在安卓系统中,电话录音应用程序不可能那么容易制作

您在创建AVD时是否提供SD卡支持?尺寸呢?是的!大小为100mb。。文件已创建。但是空的。当我以VOICE_UPLINK的形式提供音频源时,它可以工作,但仍然提供NullPointerException。您在设备中检查过吗?是的。。设备中的filenotfound错误附带一条注释,说明权限被拒绝。索尼爱立信现场有一个看那。它只是记录的声音基本上与样本代码。试试这个。并且,将此代码集成到您的项目中。
public class ServiceReceiver extends BroadcastReceiver {
PhoneStateListener listener; 
TelephonyManager telephony;
MediaRecorder recorder = new MediaRecorder();

@Override
public void onReceive(Context context, Intent intent) {

    telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);

    listener = new PhoneStateListener() {

        @Override
        public void onCallStateChanged(int state, String incomingNumber) {

            switch(state)
            {

               case TelephonyManager.CALL_STATE_OFFHOOK:
                    Log.d("DEBUG", "OFFHOOK");        
                    StartRecording();
                    break;
               case TelephonyManager.CALL_STATE_IDLE:
                   Log.d("DEBUG", "IDLE");        
                    StopRecording();
                   break;
               case TelephonyManager.CALL_STATE_RINGING:
                   Log.d("DEBUG", "RINGING");
                   break;
            }

        }

        public void StartRecording(){

             recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
             recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
             recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
             recorder.setOutputFile(this.getFullSdPath());

             try {
                recorder.prepare();
                Log.i(this.getClass().getName(), "Prepared");
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                Log.i(this.getClass().getName(), "ERR 1");
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                Log.i(this.getClass().getName(), "ERR 2");
            }

            recorder.start();   // Recording is now started
            Log.i(this.getClass().getName(), "Start Recording");
        }

        public void StopRecording(){

             recorder.stop();          
             recorder.release();
             recorder = null;
             Log.i(this.getClass().getName(), "Stop Recording");
        }

        public String getFullSdPath(){
            File sdCard = new File(Environment.getExternalStorageDirectory()    + "/RecordMyVoice");
            if (!sdCard.exists()) {
                sdCard.mkdir();
            }
            File file = new File(Environment.getExternalStorageDirectory()+"/RecordMyVoice/",new Date().getTime()+".mp4");
            System.out.println("Full path of record sound is : "+file.getAbsolutePath());
            return file.getAbsolutePath();
        }           
    };          
    telephony.listen(listener, PhoneStateListener.LISTEN_CALL_STATE);           
}
    }