in android Studio WebView, Camera is not open

Ney

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

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.
 

Max

Administrator
Staff member
Perhaps you are trying to use camera in the emulator.
It looks like a platform limitation.
 

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.
 

Attachments

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.
 

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
 

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.
 

Max

Administrator
Staff member

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
 

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?
 

Max

Administrator
Staff member
but i am not able to see the recorded Video in webView
Did you record video using WebView?
Could you please attach code how do you play recorded video?
 

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.
 

Attachments

Max

Administrator
Staff member

Max

Administrator
Staff member
Top