in android Studio WebView, Camera is not open

Discussion in 'Web Call Server 5' started by Ney, Jul 21, 2017.

  1. Ney

    Ney Member

    Hi,
    I am using Android Platform, when i open the WebView then Camera is not open.
    so please resolve it
  2. Max

    Max Administrator Staff Member

    Please provide more details / code to reproduce this:
    • Android Studio version.
    • WebView version.
    • Screenshot.
    • Web SDK / Android SDK example you are trying to open.
    Any other details which can help to reproduce.
  3. Max

    Max Administrator Staff Member

    Perhaps you are trying to use camera in the emulator.
    It looks like a platform limitation.
  4. Ney

    Ney Member

    Android Studio version 2.2.2
    WebView version- This is the functionality of Android studio
    i am using Real Mobile Device (Motorola G3) OS version 6.1
    And when we open Direct URL in Chorme, its open the Camera.

    Attached Files:

  5. Max

    Max Administrator Staff Member

    We have tested with WebView and it works for us.
    Make sure, you open URL over https:// in the WebView
    It won't work if you test with http:// because WebRTC requires https page to get access to the Webcam.

    So, make sure you have imported SSL certificate and it works over https and wss.
    Example:
    This page is open over https and has valid SSL certificate
    https://wcs5-eu.flashphoner.com/cli...ming/two_way_streaming/two_way_streaming.html
    This page uses connection over wss://
    wss://wcs5-eu.flashphoner.com:8443 (usess the same SSL certificate for domain wcs5-eu.flashphoner.com)

    You can import SSL certificates over Dashboard / Security / Certificates
    or using this manual.
  6. Ney

    Ney Member

    Hi
    I am using https:// and i am not able to open the Camera in Webview
    I checked many Devices like Motorola, ASUS, Micro Max but getting same issue.
    I attached the sample .apk Drive Link
    https://drive.google.com/open?id=0B8NNaG_6jwupNWtNTVczWC1OQ3M
    This sample app have Two Button
    First one ( Open Url in App)- Url will open in WebView but not able to see camera.
    Second One(Open Url in outside the App)- Url will directly open in Chrome and its working.
    Please Check
  7. Max

    Max Administrator Staff Member

    What is your https url?
    https URL should contain FQDN and should be covered by valid SSL certificate
    If it is sensitive information, please send this URL to logs@flashphoner.com
    Please share a code sample which we can build in our Android Studio.
  8. Ney

    Ney Member

  9. Max

    Max Administrator Staff Member

  10. Ney

    Ney Member

    i want to see the recorded Video in webView
    but i am not able to see the recorded Video in webView .
    Please check
  11. Max

    Max Administrator Staff Member

    So what about camera in WebView?
    Does it work for you?
    If yes, could you share how did you fix that?
  12. Max

    Max Administrator Staff Member

    Did you record video using WebView?
    Could you please attach code how do you play recorded video?
  13. Ney

    Ney Member

    Attached Files:

  14. Max

    Max Administrator Staff Member

    Hello
    We have managed your code and it works on our end.
    1. Add following permission in file AndroidManifest.xml
    Code:
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    2. Request permissions in run time in the onStart method
    It is mandatory starting from Android 6 Marshallow
    https://developer.android.com/train...tml#version_specific_details_permissions_in_m
    Code:
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                int hasCameraPermission = checkSelfPermission(Manifest.permission.CAMERA);
                Log.d(TAG, "has camera permission: " + hasCameraPermission);
                int hasRecordPermission = checkSelfPermission(Manifest.permission.RECORD_AUDIO);
                Log.d(TAG, "has record permission: " + hasRecordPermission);
                int hasAudioPermission = checkSelfPermission(Manifest.permission.MODIFY_AUDIO_SETTINGS);
                Log.d(TAG, "has audio permission: " + hasAudioPermission);
                List<String> permissions = new ArrayList<>();
                if (hasCameraPermission != PackageManager.PERMISSION_GRANTED) {
                    permissions.add(Manifest.permission.CAMERA);
                }
                if (hasRecordPermission != PackageManager.PERMISSION_GRANTED) {
                    permissions.add(Manifest.permission.RECORD_AUDIO);
                }
                if (hasAudioPermission != PackageManager.PERMISSION_GRANTED) {
                    permissions.add(Manifest.permission.MODIFY_AUDIO_SETTINGS);
                }
    
                if (!permissions.isEmpty()) {
                    requestPermissions(permissions.toArray(new String[permissions.size()]),111);
    
                }
            }
    Here we gather non granted permissions and request them all.
    As a result pop-up dialog will be raised.
    3. Add following listener code to grant selected permissions in the WebView.
    Code:
    webView.setWebChromeClient(new WebChromeClient() {
                @TargetApi(Build.VERSION_CODES.LOLLIPOP)
                @Override
                public void onPermissionRequest(final PermissionRequest request) {
                    WebViewActivity.this.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            request.grant(request.getResources());
                        }
                    });
                }
    
                @Override
                public void onPermissionRequestCanceled(PermissionRequest request) {
                    Log.d(TAG, "onPermissionRequestCanceled");
                }
            });
    This works for us. Please check on your end.
    I have attached WebViewActivity.java and AndroidManifest.xml code samples.

    Attached Files:

  15. Ney

    Ney Member

  16. Max

    Max Administrator Staff Member

    Do you mean it does not work in two-way streaming mode?
    Could you please check our Two Way Streaming url in your WebView application?
    Does this work for you?
    https://wcs5-eu.flashphoner.com/cli...ming/two_way_streaming/two_way_streaming.html
  17. Ney

    Ney Member

  18. Max

    Max Administrator Staff Member

    Yes, I mean test your WebView app with our default URL and check if it works.
  19. Ney

    Ney Member

  20. Max

    Max Administrator Staff Member

Share This Page