title: Android media recorder start failed
body: <p>i am using below code to record audio in my application</p>
  
  <pre><code>private void startRecording() {
  
      if (mRecorder == null) {
          mRecorder = new MediaRecorder();
      }
  
      mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
      mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
      mRecorder.setOutputFile(path);
      mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
  
      try {
          mRecorder.prepare();
      } catch (IOException e) {
          Log.i(TAG, e.getMessage());
      }
      mRecorder.start();
  
  }
  </code></pre>
  
  <p>above code works perfectly on android lollipop 5.1 but getting below error on android nougat 7.1.1</p>
  
  <pre><code>05-25 14:51:45.245 21686-21686/com.chatting.test E/AndroidRuntime: FATAL EXCEPTION: main
                                                                  Process: com.chatting.test, PID: 21686
                                                                  java.lang.RuntimeException: start failed.
                                                                      at android.media.MediaRecorder.start(Native Method)
                                                                      at com.chatting.test.Activities.Chats.PrivateChatActivity.startRecording(PrivateChatActivity.java:1363)
                                                                      at com.chatting.test.Activities.Chats.PrivateChatActivity.onTouch(PrivateChatActivity.java:219)
                                                                      at android.view.View.dispatchTouchEvent(View.java:10019)
                                                                      at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2632)
                                                                      at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2264)
                                                                      at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2632)
                                                                      at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2264)
                                                                      at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2632)
                                                                      at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2264)
                                                                      at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2632)
                                                                      at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2264)
                                                                      at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2632)
                                                                      at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2264)
                                                                      at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2632)
                                                                      at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2264)
                                                                      at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2632)
                                                                      at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2264)
                                                                      at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:413)
                                                                      at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1808)
                                                                      at android.app.Activity.dispatchTouchEvent(Activity.java:3061)
                                                                      at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:71)
                                                                      at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:375)
                                                                      at android.view.View.dispatchPointerEvent(View.java:10243)
                                                                      at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4438)
                                                                      at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4306)
                                                                      at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3853)
                                                                      at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3906)
                                                                      at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3872)
                                                                      at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3999)
                                                                      at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3880)
                                                                      at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4056)
                                                                      at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3853)
                                                                      at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3906)
                                                                      at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3872)
                                                                      at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3880)
                                                                      at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3853)
                                                                      at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6246)
                                                                      at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6220)
                                                                      at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6181)
                                                                      at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6349)
                                                                      at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
                                                                      at android.os.MessageQueue.nativePollOnce(Native Method)
                                                                      at android.os.MessageQueue.next(MessageQueue.java:323)
                                                                      at android.os.Looper.loop(Looper.java:136)
                                                                      at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                                      at java.lang.reflect.Method.invoke(Native Method)
                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
  </code></pre>
  
  <p>i have already granted below permissions on runtime on nougat 7.1.1</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.RECORD_AUDIO" /&gt;
  &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  </code></pre>
  
  <p>how can i make above code work with android nougat 7.1.1 ?</p>