title: Error While Enabling Speaker on Outgoing Call in Oreo/Nougat
body: <p>I need to turn on loudspeaker during outgoing calls but its throwing exception Below is the code snippet i have used:</p>
  
  <pre><code>audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
                      audioManager.setMode(AudioManager.MODE_IN_CALL);
                      if (!audioManager.isSpeakerphoneOn())
                          audioManager.setSpeakerphoneOn(true);
                      audioManager.setMode(AudioManager.MODE_NORMAL);
  </code></pre>
  
  <p>It is working good from devices below 6.0, but not working in 8.0 and 7.0. </p>
  
  <p><strong>logcat:</strong></p>
  
  <pre><code>01-22 13:38:19.887 25014-25014/com.tool.autoredialer D/AudioManager: PPD setMode mode = 2
  01-22 13:38:19.888 25014-25014/com.tool.autoredialer V/AudioManager: Elem: dalvik.system.VMStack.getThreadStackTrace(Native Method)
  01-22 13:38:19.888 25014-25014/com.tool.autoredialer V/AudioManager: Elem: java.lang.Thread.getStackTrace(Thread.java:1536)
  01-22 13:38:19.888 25014-25014/com.tool.autoredialer V/AudioManager: Elem: android.media.AudioManager.setMode(AudioManager.java:1630)
  01-22 13:38:19.888 25014-25014/com.tool.autoredialer V/AudioManager: Elem: com.tool.autoredialer.services.CallVibratorAccessibilityService.handlVibrate(CallVibratorAccessibilityService.java:114)
  01-22 13:38:19.888 25014-25014/com.tool.autoredialer V/AudioManager: Elem: com.tool.autoredialer.services.CallVibratorAccessibilityService.onAccessibilityEvent(CallVibratorAccessibilityService.java:49)
  01-22 13:38:19.888 25014-25014/com.tool.autoredialer V/AudioManager: Elem: android.accessibilityservice.AccessibilityService$2.onAccessibilityEvent(AccessibilityService.java:1527)
  01-22 13:38:19.888 25014-25014/com.tool.autoredialer V/AudioManager: Elem: android.accessibilityservice.AccessibilityService$IAccessibilityServiceClientWrapper.executeMessage(AccessibilityService.java:1712)
  01-22 13:38:19.888 25014-25014/com.tool.autoredialer V/AudioManager: Elem: com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:37)
  01-22 13:38:19.888 25014-25014/com.tool.autoredialer V/AudioManager: Elem: android.os.Handler.dispatchMessage(Handler.java:105)
  01-22 13:38:19.888 25014-25014/com.tool.autoredialer V/AudioManager: Elem: android.os.Looper.loop(Looper.java:164)
  01-22 13:38:19.888 25014-25014/com.tool.autoredialer V/AudioManager: Elem: android.app.ActivityThread.main(ActivityThread.java:6809)
  01-22 13:38:19.888 25014-25014/com.tool.autoredialer V/AudioManager: Elem: java.lang.reflect.Method.invoke(Native Method)
  01-22 13:38:19.888 25014-25014/com.tool.autoredialer V/AudioManager: Elem: com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
  01-22 13:38:19.888 25014-25014/com.tool.autoredialer V/AudioManager: Elem: com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
  01-22 13:38:19.892 25014-25014/com.tool.autoredialer I/AudioManager: setSpeakerphoneOn true java.lang.Throwable
                                                                           at android.media.AudioManager.setSpeakerphoneOn(AudioManager.java:1235)
                                                                           at com.tool.autoredialer.services.CallVibratorAccessibilityService.handlVibrate(CallVibratorAccessibilityService.java:116)
                                                                           at com.tool.autoredialer.services.CallVibratorAccessibilityService.onAccessibilityEvent(CallVibratorAccessibilityService.java:49)
                                                                           at android.accessibilityservice.AccessibilityService$2.onAccessibilityEvent(AccessibilityService.java:1527)
                                                                           at android.accessibilityservice.AccessibilityService$IAccessibilityServiceClientWrapper.executeMessage(AccessibilityService.java:1712)
                                                                           at com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:37)
                                                                           at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                           at android.os.Looper.loop(Looper.java:164)
                                                                           at android.app.ActivityThread.main(ActivityThread.java:6809)
                                                                           at java.lang.reflect.Method.invoke(Native Method)
                                                                           at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
  01-22 13:38:19.894 25014-25014/com.tool.autoredialer D/AudioManager: com.tool.autoredialerdo not have using speaker authority in call
  01-22 13:38:19.894 25014-25014/com.tool.autoredialer D/AudioManager: PPD setMode mode = 0
  01-22 13:38:19.894 25014-25014/com.tool.autoredialer V/AudioManager: Elem: dalvik.system.VMStack.getThreadStackTrace(Native Method)
  01-22 13:38:19.894 25014-25014/com.tool.autoredialer V/AudioManager: Elem: java.lang.Thread.getStackTrace(Thread.java:1536)
  01-22 13:38:19.894 25014-25014/com.tool.autoredialer V/AudioManager: Elem: android.media.AudioManager.setMode(AudioManager.java:1630)
  01-22 13:38:19.894 25014-25014/com.tool.autoredialer V/AudioManager: Elem: com.tool.autoredialer.services.CallVibratorAccessibilityService.handlVibrate(CallVibratorAccessibilityService.java:117)
  01-22 13:38:19.894 25014-25014/com.tool.autoredialer V/AudioManager: Elem: com.tool.autoredialer.services.CallVibratorAccessibilityService.onAccessibilityEvent(CallVibratorAccessibilityService.java:49)
  01-22 13:38:19.894 25014-25014/com.tool.autoredialer V/AudioManager: Elem: android.accessibilityservice.AccessibilityService$2.onAccessibilityEvent(AccessibilityService.java:1527)
  01-22 13:38:19.894 25014-25014/com.tool.autoredialer V/AudioManager: Elem: android.accessibilityservice.AccessibilityService$IAccessibilityServiceClientWrapper.executeMessage(AccessibilityService.java:1712)
  01-22 13:38:19.894 25014-25014/com.tool.autoredialer V/AudioManager: Elem: com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:37)
  01-22 13:38:19.894 25014-25014/com.tool.autoredialer V/AudioManager: Elem: android.os.Handler.dispatchMessage(Handler.java:105)
  01-22 13:38:19.894 25014-25014/com.tool.autoredialer V/AudioManager: Elem: android.os.Looper.loop(Looper.java:164)
  01-22 13:38:19.894 25014-25014/com.tool.autoredialer V/AudioManager: Elem: android.app.ActivityThread.main(ActivityThread.java:6809)
  01-22 13:38:19.895 25014-25014/com.tool.autoredialer V/AudioManager: Elem: java.lang.reflect.Method.invoke(Native Method)
  01-22 13:38:19.895 25014-25014/com.tool.autoredialer V/AudioManager: Elem: com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
  01-22 13:38:19.895 25014-25014/com.tool.autoredialer V/AudioManager: Elem: com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
  </code></pre>