问题
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:
- Request a permission from the Android system if needed by implementing
GeckoSession.PermissionDelegate.onAndroidPermissionsRequest()
. - Process the content permission request from the website by implementing
GeckoSession.PermissionDelegate.onContentPermissionRequest()
- which comes down to callinggrant()
orreject()
on the providedcallback
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