instascan icon indicating copy to clipboard operation
instascan copied to clipboard

Camera not working in ios & android app:

Open online123be opened this issue 6 years ago • 2 comments

When running instagram it is working fine in webbrowser & phonebrowser (safari, chrome, ...) on ios, windows, mac, ... But when I open the exact same page via webview on phonegap webview app i dont get any camera feed. (also no permission is being asked, it is declared in the info.plist) When inspect with safari on the app developer mode I get this error: Unhandled Promise Rejection: Error: Cannot access video stream (TypeError).

on line 30429: _var _this = possibleConstructorReturn(this, (MediaError.proto || Object.getPrototypeOf(MediaError)).call(this, 'Cannot access video stream (' + type + ').'));

Anyone know how to fix this? Thanks a lot!

The url: https://devapp.easybooker.be/qrscanner.php

online123be avatar Apr 27 '18 10:04 online123be

I dont know if it can help you, but i just was in a similar case (but android native) and it started working via webview (WebRTC) after asking the permissions on run since it seems like since API 23 user needs to grant permissions to app while the app is running, not when they install the app. https://stackoverflow.com/questions/45837123/how-to-get-permission-to-access-camera-in-android-webview/45837161

So maybe it's an issue with phonegap camera permissions on android 6/+?

This java code helped me for android 6/+ :

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ...
  
    String permission = Manifest.permission.CAMERA;
    int grant = ContextCompat.checkSelfPermission(this, permission);
     
    if (grant != PackageManager.PERMISSION_GRANTED) {
        String[] permission_list = new String[1];
        permission_list[0] = permission;
        ActivityCompat.requestPermissions(this, permission_list, 1);
    } 
    
    webView.setWebChromeClient(new WebChromeClient() {
    
                @TargetApi(Build.VERSION_CODES.LOLLIPOP)
                @Override
                public void onPermissionRequest(final PermissionRequest request) {
                    request.grant(request.getResources());
                }
    }
}

medskill avatar May 24 '18 19:05 medskill

i've added that code but it doesnt work... is there any detail that i missed?

I dont know if it can help you, but i just was in a similar case (but android native) and it started working via webview (WebRTC) after asking the permissions on run since it seems like since API 23 user needs to grant permissions to app while the app is running, not when they install the app. https://stackoverflow.com/questions/45837123/how-to-get-permission-to-access-camera-in-android-webview/45837161

So maybe it's an issue with phonegap camera permissions on android 6/+?

This java code helped me for android 6/+ :

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ...
  
    String permission = Manifest.permission.CAMERA;
    int grant = ContextCompat.checkSelfPermission(this, permission);
     
    if (grant != PackageManager.PERMISSION_GRANTED) {
        String[] permission_list = new String[1];
        permission_list[0] = permission;
        ActivityCompat.requestPermissions(this, permission_list, 1);
    } 
    
    webView.setWebChromeClient(new WebChromeClient() {
    
                @TargetApi(Build.VERSION_CODES.LOLLIPOP)
                @Override
                public void onPermissionRequest(final PermissionRequest request) {
                    request.grant(request.getResources());
                }
    }
}

akbarnotopb avatar Jun 17 '19 14:06 akbarnotopb