Моё веб приложение использует камеру, webview тянет его по обычной ссылке, домен https - запросить камеру могу. Но мне почему-то не даёт это сделать сам android.
Нашёл только такое решение, не работает, но ошибка из просто "Permission denied" превращается в ту, что ниже:
myWebView.setWebChromeClient(new WebChromeClient() {
@Override
public void onPermissionRequest(PermissionRequest request) {
request.grant(request.getResources());
}
});
Ошибка
2023-05-02 18:22:54.064 4165-4165/com.morservice E/DecorView[]: Destroying unexpected ActionMode instance of TYPE_FLOATING; com.android.internal.view.FloatingActionMode@4cc5828 was not the current floating action mode! Expected null
2023-05-02 18:22:54.325 4165-4187/com.morservice D/OpenGLRenderer: endAllActiveAnimators on 0xec593430 (RippleDrawable) with handle 0xf2c6f9b0
2023-05-02 18:22:57.199 4165-4247/com.morservice I/CameraManagerGlobal: Connecting to camera service
2023-05-02 18:22:57.295 4165-4247/com.morservice E/cr_VideoCapture: allocate: manager.openCamera:
java.lang.SecurityException: validateClientPermissionsLocked:1165: Caller "com.morservice" (PID 10122, UID 4165) cannot open camera "0" without camera permission
at android.hardware.camera2.CameraManager.throwAsPublicException(CameraManager.java:1003)
at android.hardware.camera2.CameraManager.openCameraDeviceUserAsync(CameraManager.java:548)
at android.hardware.camera2.CameraManager.openCameraForUid(CameraManager.java:725)
at android.hardware.camera2.CameraManager.openCamera(CameraManager.java:653)
at mM.startCaptureMaybeAsync(chromium-TrichromeWebViewGoogle.apk-stable-410410681:11)
Caused by: android.os.ServiceSpecificException: validateClientPermissionsLocked:1165: Caller "com.morservice" (PID 10122, UID 4165) cannot open camera "0" without camera permission (code 1)
at android.os.Parcel.createExceptionOrNull(Parcel.java:2387)
at android.os.Parcel.createException(Parcel.java:2357)
at android.os.Parcel.readException(Parcel.java:2340)
at android.os.Parcel.readException(Parcel.java:2282)
at android.hardware.ICameraService$Stub$Proxy.connectDevice(ICameraService.java:634)
at android.hardware.camera2.CameraManager.openCameraDeviceUserAsync(CameraManager.java:511)
at android.hardware.camera2.CameraManager.openCameraForUid(CameraManager.java:725)
at android.hardware.camera2.CameraManager.openCamera(CameraManager.java:653)
at mM.startCaptureMaybeAsync(chromium-TrichromeWebViewGoogle.apk-stable-410410681:11)
2023-05-02 18:22:57.299 4165-4165/com.morservice I/chromium: [INFO:CONSOLE(0)] "Uncaught (in promise) NotReadableError: Could not start video source", source: https://morservicetest.na4u.ru/add-product (0)
2023-05-02 18:23:03.497 4165-4165/com.morservice I/chromium: [INFO:CONSOLE(33)] "Uncaught TypeError: Cannot read property 'getTracks' of undefined", source: https://morservicetest.na4u.ru/js/global.js (33)
MainActivitypackage com.morservice;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.webkit.PermissionRequest;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
public class MainActivity extends AppCompatActivity {
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.setWebChromeClient(new WebChromeClient() {
@Override
public void onPermissionRequest(PermissionRequest request) {
request.grant(request.getResources());
}
});
myWebView.loadUrl("https://morservicetest.na4u.ru/frame");
}
}
Manifest<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.webkit.PermissionRequest" />
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.МорСервис"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
</application>
</manifest>