Geckoview get microphone permission

跟風遠走 提交于 2019-12-10 22:17:24

问题


I am trying to use the audio recording feature from a website inside a GeckoView element. Therefore I set the permission inside AndroidManifest.xml:

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

When I now try to record the audio on the website, an HTML PopUp (which is part of the website, not a feature of the browser) tells me that I need to give permission. I can't do anything else - it's just a note without buttons.

On the other hand: when I use the regular Firefox browser, the browser asks me if I want to grant permission to my mic for this website while this HTML PopUp is shown.

I don't get asked that by GeckoView and therefore need to find a way to grant permission to use the mic for this website inside GeckoView. Do I need to give permission inside GeckoView? I looked up the documentation on permissions of GeckoView but could not get it to work (probably because of my basic coding knowledge).

Highly appreciate any help!

Thanks a lot!


回答1:


GeckoView itself does not show any permission dialogs. However it provides a delegate for it that you can implement yourself: GeckoSession.setPromptDelegate().

You basically have to do two things:

  1. Request a permission from the Android system if needed by implementing GeckoSession.PermissionDelegate.onAndroidPermissionsRequest().
  2. Process the content permission request from the website by implementing GeckoSession.PermissionDelegate.onContentPermissionRequest() - which comes down to calling grant() or reject() on the provided callback object.

The Mozilla's Android Components project provides implementations for this and many other "browser features" on top of GeckoView - if you do not want to have a custom implementation. Browsers like "Firefox Preview" use the implementations from this project.



来源:https://stackoverflow.com/questions/56709874/geckoview-get-microphone-permission

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!