2015-10-24 8 views
15

私はを根付きましたロリポップ付きのNexus電話。私は入って来る&発信を記録しようとしています。MediaRecorderを使用して通話を録音できません

私のアプリケーションは、私はサイズ> 0bytesでファイルを作成することができるよ<force-lock />

のポリシーにDeviceAdminReceiverを拡張します。しかし、私はそれを再生すると、それは空白です。

以下のコードを見てください:たManifest.xml

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
<uses-permission android:name="android.permission.RECORD_AUDIO" /> 
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" /> 
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> 
<uses-permission android:name="android.permission.STORAGE" /> 
..... 
<service android:name=".RCService" 
    android:exported="false" > 
</service> 
..... 
<receiver 
      android:name=".utils.MyDeviceAdminReceiver" 
      android:permission="android.permission.BIND_DEVICE_ADMIN" > 
      <intent-filter> 

       <!-- This action is required --> 
       <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" /> 
       <action android:name="android.app.action.DEVICE_ADMIN_DISABLED" /> 
       <action android:name="android.app.action.DEVICE_ADMIN_DISABLE_REQUESTED" /> 
      </intent-filter> 

      <!-- This is required this receiver to become device admin component. --> 
      <meta-data 
       android:name="android.app.device_admin" 
       android:resource="@xml/device_admin" /> 
     </receiver> 


     <receiver android:name=".CallRecoderBroadcast"> 
      <intent-filter> 
       <action android:name="android.intent.action.PHONE_STATE" /> 
       <action android:name="android.intent.action.NEW_OUTGOING_CALL" /> 
      </intent-filter> 
     </receiver> 

device_admin.xml

<device-admin xmlns:android="http://schemas.android.com/apk/res/android" > 
    <uses-policies> 
     <force-lock /> 
    </uses-policies> 
</device-admin> 

CallRecoderBroadcast.java

/** 
* Lifecycle : 
* Incoming call : RINGING -> OFFHOOK -> IDLE 
* Outgoing Call : OFFHOOK -> IDLE 
*/ 
public class CallRecoderBroadcast extends BroadcastReceiver { 

    private static final String TAG = "CallRecoderBroadcast"; 
    private static final String ACTION_PHONE = "android.intent.action.PHONE_STATE"; 
    private static final String OUTGOING_CALL = "android.intent.action.NEW_OUTGOING_CALL"; 

    private static Boolean mCallOnGoing = Boolean.FALSE; 
    private MediaRecorder mRecorder = new MediaRecorder(); 
// private File mFile = null; 
    private String mNumber; 

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

     try { 

      if (intent.getAction().equals(ACTION_PHONE)) { 

       Bundle bundle = intent.getExtras(); 
       String state = bundle.getString(TelephonyManager.EXTRA_STATE); 

       Log.e(TAG, state); 

       if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) { 

        Log.e(TAG, bundle.getString(TelephonyManager.EXTRA_INCOMING_NUMBER)); 
        mNumber = bundle.getString(TelephonyManager.EXTRA_INCOMING_NUMBER); 


       } else if (state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) { 

        if (!mCallOnGoing) { 
         recordCall(context); 
        } 


       } else if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)) { 

        if (mCallOnGoing) { 
         stopRecording(); 
        } 

       } 

      } else if (intent.getAction().equals(OUTGOING_CALL)) { 
       Log.e(TAG, "OUTGOING cALL"); 
       Log.e(TAG, intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER)); 
       mNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); 


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

    } 

    private void recordCall(Context context) throws IOException, CustomExcpetion { 

     File file = prepareFile(context); 

     if (file.exists()) { 
      mCallOnGoing = Boolean.TRUE; 
      mRecorder.setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION); 
      mRecorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB); 
      mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); 
      mRecorder.setOutputFile(file.getAbsolutePath()); 
      mRecorder.prepare(); 
      mRecorder.start(); 
     } 

    } 

    private void stopRecording() { 
     mCallOnGoing = Boolean.FALSE; 
//   mRecorder.stop(); 
     mRecorder.release(); 
    } 

    private File prepareFile(Context context) throws CustomExcpetion { 
     File outputFile = null; 
     try { 
      File dir = new File(context.getFilesDir(), "recorderdFiles"); 
      if (!dir.exists()) { 
       dir.mkdirs(); 
      } 

      Long timeStamp = System.currentTimeMillis(); 

      outputFile = new File(dir, timeStamp.toString()); 
      if (!outputFile.exists()) { 
       outputFile.createNewFile(); 
      } 
     } catch (IOException exp) { 
      throw new CustomExcpetion(context, exp); 
     } 
     return outputFile; 
    } 
} 

P.私はhereを与えられた例でも試しましたが、同時にアップリンクではない&ダウンリンクのためのMic &の作業形態だけが同時に動作しました。

+0

[このリンクをチェック](http://stackoverflow.com/questions/24139332/voice-call-recording-in-android-using-mediarecorder)このリンクをチェックする –

答えて

0

残念ながら、そのデバイスでは音声コールレコーダはサポートされていません。 他のデバイスで正常に動作すると思います。

関連する問題