在Android中录制语音通话

时间:2013-12-08 16:17:36

标签: android

我想在Android中录制电话。我知道我必须使用广播接收器,但是我必须使用广播接收器是否必须使用意图或服务?如果答案是服务,那么任何人都可以为此或两者提供代码吗?

提前谢谢。

这是我的接收器代码

public class BrCallReceive extends BroadcastReceiver {

          @Override
        public void onReceive(Context c, Intent i) {

            Bundle extras = i.getExtras();
            Intent x = new Intent (c, EavesDropperActivity.class);
            x.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            if (extras != null) {
                String state = extras.getString(TelephonyManager.EXTRA_STATE);
                Log.w("DEBUG", state);
                if (state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
                Log.w("DEBUG", "MATCHES");
                Toast.makeText(c,
                        "Launching record APP !",
                Toast.LENGTH_LONG).show();
                c.startActivity(x);
            }
        }
    }





}   




<blink>

public class EavesDropperActivity extends Activity {

 /** Called when the activity is first created. */
    MediaRecorder m_recorder = new MediaRecorder();
    TelephonyManager t_manager ;
    PhoneStateListener p_listener ;
    String record_state;
    Uri file;

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.main);
    Toast.makeText(getBaseContext(),
            "Executing Activity",
    Toast.LENGTH_LONG).show();

    t_manager = (TelephonyManager) getSystemService (Context.TELEPHONY_SERVICE);
    p_listener = new PhoneStateListener() {
        @Override
        public void onCallStateChanged (int state, String incomingNumber) {
            switch (state) {
                case (TelephonyManager.CALL_STATE_IDLE)     :
                                                            stop_recorder();
                                                                                           Toast.makeText(getBaseContext(),
                                                            "recorder state : stop" ,
                                                            Toast.LENGTH_LONG).show();
                                                                                           //t_manager.listen(p_listener, PhoneStateListener.LISTEN_NONE);
                                                            //finish();
                                                            break;

                case (TelephonyManager.CALL_STATE_OFFHOOK)     :
                                                                                            Toast.makeText(getBaseContext(),
                                                            "recorder state : start" ,

                                                            break;
                case (TelephonyManager.CALL_STATE_RINGING)     :

                                                            break;

            }
        }
    };
    t_manager.listen(p_listener, PhoneStateListener.LISTEN_CALL_STATE);
    return;

}

public void start_recorder () {
    m_recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    m_recorder.setOutputFormat(OutputFormat.THREE_GPP);
    m_recorder.setOutputFile(Environment.getExternalStorageDirectory() +                    "/songs/audionew.3gpp");
    m_recorder.setAudioEncoder(AudioEncoder.AMR_NB);

        try {
            m_recorder.prepare();
            m_recorder.start();
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

  public void stop_recorder () {
    m_recorder.stop();
    m_recorder.release();
      Uri file = Uri.fromFile(
new File(Environment.getExternalStorageDirectory(),"/songs/audionew.3gpp"));
    Toast.makeText(getBaseContext(),
            "record stored at " + file.toString(),
    Toast.LENGTH_LONG).show();

    t_manager.listen(p_listener, PhoneStateListener.LISTEN_NONE);
    finish();
}

} 

</blink>


My manifest :

<blink>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testapp"
android:versionCode="1"
android:versionName="1.0" >


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

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.testapp.EavesDropperActivity"
                android:label="@string/app_name" >
        </activity>

        <receiver android:name="BrCallReceive" >
            <intent-filter>
                <action android:name="android.intent.action.PHONE_STATE" >
                </action>
            </intent-filter>
        </receiver>
    </application>

</manifest>

</blink>

1 个答案:

答案 0 :(得分:2)

出于安全原因,您无法在Android上录制语音通话。无论是否有root,您都无法访问通话中的音频流。

这样做是为了防止恶意软件窃取个人数据等。