gpt4 book ai didi

java - html相机视频流不显示在android webview中

转载 作者:行者123 更新时间:2023-12-01 16:28:34 25 4
gpt4 key购买 nike

我有一个网站,我使用 android studio 将其转换为 apk。该应用程序工作正常,但是当我尝试使用相机时,它显示此图像: screenshot

相机流显示在我手机上的浏览器中。当我用谷歌搜索这个问题时,解决方案正在使用 androidx 之前已弃用的旧代码,并且不再工作。 I cant get this solution to work我该如何解决?

mainactivity:
package name;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.content.Intent;
import android.os.Handler;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.graphics.Bitmap;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

String ShowOrHideWebViewInitialUse = "show";
private WebView webview ;
private ProgressBar spinner;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);



webview = findViewById(R.id.webView);
spinner = findViewById(R.id.progressBar1);
webview.setWebViewClient(new CustomWebViewClient());

webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setDomStorageEnabled(true);
webview.setOverScrollMode(WebView.OVER_SCROLL_NEVER);
webview.loadUrl("url");


}


private class CustomWebViewClient extends WebViewClient {

@Override
public void onPageStarted(WebView webview, String url, Bitmap favicon) {

if (ShowOrHideWebViewInitialUse.equals("show")) {
webview.setVisibility(View.INVISIBLE);
}
}

@Override
public void onPageFinished(WebView view, String url) {

ShowOrHideWebViewInitialUse = "hide";
spinner.setVisibility(View.GONE);

view.setVisibility(View.VISIBLE);
super.onPageFinished(view, url);

}
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
if (webview.canGoBack()) {
webview.goBack();
} else {
finish();
}
return true;
}

}
return super.onKeyDown(keyCode, event);
}
}

list :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="name">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.CAMERA2" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.intent.action.CAMERA_BUTTON" />

<uses-feature
android:name="android.hardware.camera"
android:required="true" />
<application
android:usesCleartextTraffic="true"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:exported="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>

Activity 主要 xml:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"
tools:context="name"> <WebView
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:id="@+id/webView" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" android:visibility="gone" />
<ProgressBar
android:id="@+id/progressBar1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:layout_centerInParent="true" />
<TextView
android:id="@+id/fullscreen_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:keepScreenOn="true"
android:textColor="#33b5e5"
android:textSize="50sp"
android:textStyle="bold" />

<!-- This FrameLayout insets its children based on system windows using
android:fitsSystemWindows. -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<LinearLayout
android:id="@+id/fullscreen_content_controls"
style="?metaButtonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:background="@color/black_overlay"
android:orientation="horizontal"
tools:ignore="UselessParent">



</LinearLayout>
</FrameLayout>
</RelativeLayout>

最佳答案

尝试使用 onPermissionRequest 指定 WebChromeClient

以下内容将授予一切权限


webview.setWebChromeClient(new WebChromeClient() {

@Override
public void onPermissionRequest(final PermissionRequest request) {
request.grant(request.getResources());
}

});

关于java - html相机视频流不显示在android webview中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62104165/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com