Does getUserMedia works in ionic-webview in Android app?

前端 未结 2 761
悲哀的现实
悲哀的现实 2020-12-22 02:11

I have given all the permissions for camera and microphone. Enable CSP in meta tag for the iframe. Still not able to get permission for camera and microphone in getusermedia

2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-22 02:47

    Update - 04/11/2018 - Working Ionic example

    As promised I had a crack at this today. To answer your question now in full: Yes you can access getUserMedia inside of ionic on Android.

    See my GitHub project here for a working example and for screenshots.

    See this feature branch here which successfully tests getUserMedia inside of an iframe

    Steps involved:

    • Install Ionic
    • ionic start getUserMedia blank
    • cd getUserMedia
    • ionic cordova plugin add cordova-plugin-android-permissions
    • npm install --save @ionic-native/android-permissions
    • npm install webrtc-adapter --save
    • link to adapter in angular.json scripts (link)
    • Add AndroidPermissions to app.module.ts provider (link)
    • Create camera access code in home.component.ts (link)
    • Add android manifiest permissions to config.xml and AndroidManifest.xml (link, if the config doesn't copy go to platforms/android/app/src/AndroidManifest.xml)
    • ionic cordova platform add android
    • ionic cordova build android
    • ionic cordova run android

    You can also see alternative versions of this for React Native, native Android and Cordova.

    As of this update support for iOS is still a no due to Apple security restrictions on WKWebView and UIWebView.

    Iframes: To make sure getUserMedia works inside of them make sure you:

    • CORS of the embedded site need to have the allowed access origin header
    • enable security permissions to access the camera and microphone