Webview中的摄像头支持HTML输入标签 [英] Camera support in Webview for HTML input tag

查看:350
本文介绍了Webview中的摄像头支持HTML输入标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用一个 打开我的html页面的webview构建一个简单的应用程序。在我的手机上使用浏览器加载时,html页面会打开相机,但无法在我的webview中打开相机。我试图寻找答案,但我不确定实际问题。
有人可以帮我理解什么是错的。我在下面粘贴代码和logcat输出。



主要活动:

  package com.webview.ak.webviewapp; 

导入android.annotation.SuppressLint;
导入android.annotation.TargetApi;
导入android.content.Context;
导入android.os.Build;
导入android.support.v7.app.AppCompatActivity;
导入android.os.Bundle;
导入android.util.Log;
导入android.webkit.JavascriptInterface;
导入android.webkit.PermissionRequest;
导入android.webkit.WebChromeClient;
导入android.webkit.WebSettings;
导入android.webkit.WebView;
导入android.webkit.WebViewClient;
导入android.widget.Toast;

public class MainActivity extends AppCompatActivity {

final String TAG =MainActivity;
//最终字符串LOCAL_FILE =http://10.0.2.2/Beacon/newcam.php;
final String LOCAL_FILE =http://192.168.1.35/Beacon/newcam.php;

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


//在我们的布局中查找web视图xml
WebView myWebView =(WebView)findViewById(R.id.webview);


//设置
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setAllowFileAccessFromFileURLs(true);
webSettings.setAllowUniversalAccessFromFileURLs(true);
webSettings.setAllowContentAccess(true);
webSettings.setDisplayZoomControls(true);

//设置一个web view客户端和一个chrome客户端
myWebView.setWebViewClient(new WebViewClient());
myWebView.setWebChromeClient(new WebChromeClient(){
//需要接受使用相机和音频的权限
@TargetApi(Build.VERSION_CODES.M)

@Override
public void onPermissionRequest(final PermissionRequest request){
Log.d(TAG,onPermissionRequest);

//确保请求来自我们的文件
//警告:本地文件检查失败
request.grant(request.getResources());



}
});



//将本地HTML文件加载到webview
myWebView.loadUrl(LOCAL_FILE);
}



}

xml file:

 <?xml version =1.0encoding =utf-8?> 
< RelativeLayout
xmlns:android =http://schemas.android.com/apk/res/android
xmlns:tools =http://schemas.android.com / tools
android:layout_width =match_parent
android:layout_height =match_parent
android:orientation =vertical>


< WebView
android:id =@ + id / webview
android:layout_width =match_parent
android:layout_height = match_parent
/>
< / RelativeLayout>

清单:

 <?xml version =1.0encoding =utf-8?> 
< manifest xmlns:android =http://schemas.android.com/apk/res/android
package =com.webview.ak.webviewapp>
< uses-permission android:name =android.permission.INTERNET/>
< uses-permission android:name =android.permission.RECORD_AUDIO/>
<使用权限android:name =android.permission.CAMERA/>
< uses-permission android:name =android.permission.MODIFY_AUDIO_SETTINGS/>

< uses-feature android:name =android.hardware.cameraandroid:required =true/>
< uses-feature android:name =android.hardware.camera.frontandroid:required =true/>

< application
android:allowBackup =true
android:icon =@ mipmap / ic_launcher
android:label =@ string / app_name
android:roundIcon =@ mipmap / ic_launcher_round
android:supportsRtl =true
android:theme =@ style / AppTheme>
< activity android:name =。MainActivity>
< intent-filter>

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

< / manifest>

HTML文件:

 < HTML> 
< head>

< / head>

< body>
< input type =fileaccept =image / *>

< / body>
< / html>

Logcat输出:

  08-20 22:16:06.590 16088-16088 /? I / art:延迟启用-Xcheck:jni 
08-20 22:16:06.599 16088-16088 /? D / TidaProvider:TidaProvider()
08-20 22:16:06.606 16088-16088 /? V / BoostFramework:mAcquireFunc method = public int com.qualcomm.qti.Performance.perfLockAcquire(int,int [])
08-20 22:16:06.606 16088-16088 /? V / BoostFramework:mReleaseFunc method = public int com.qualcomm.qti.Performance.perfLockRelease()
08-20 22:16:06.606 16088-16088 /? V / BoostFramework:mAcquireTouchFunc method = public int com.qualcomm.qti.Performance.perfLockAcquireTouch(android.view.MotionEvent,android.util.DisplayMetrics,int,int [])
08-20 22:16:06.607 16088 -16088 /? V / BoostFramework:mIOPStart method = public int com.qualcomm.qti.Performance.perfIOPrefetchStart(int,java.lang.String)
08-20 22:16:06.607 16088-16088 /? V / BoostFramework:mIOPStop method = public int com.qualcomm.qti.Performance.perfIOPrefetchStop()
08-20 22:16:06.619 16088-16088 /? V / BoostFramework:BoostFramework():mPerf = com.qualcomm.qti.Performance@e7557a
08-20 22:16:06.653 16088-16088 / com.webview.ak.webviewapp W / System:ClassLoader引用未知路径:/data/app/com.webview.ak.webviewapp-2/lib/arm64
08-20 22:16:06.690 16088-16088 / com.webview.ak.webviewapp W / art:在Android 4.1之前, android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter,android.content.res.ColorStateList,android.graphics.PorterDuff $ Mode)将不正确地重写包私有方法android.graphics.drawable.Drawable
08-20 22:16:06.721 16088-16088 / com.webview.ak.webviewapp V / BoostFramework:BoostFramework():mPerf = com.qualcomm.qti.Performance@1a0cdff
08-20 22:16:06.722 16088-16088 / com.webview.ak.webviewapp V / BoostFramework:BoostFramework():mPerf = com.qualcomm.qti.Performance@27597cc
08-20 22: 16:06.793 16088-16088 / com.webview.ak.webview app I / WebViewFactory:加载com.android.chrome版本59.0.3071.125(代码307112552)
08-20 22:16:06.883 16088-16088 / com.webview.ak.webviewapp I / cr_LibraryLoader:加载本地库:5毫秒(时间戳1900-1905)
08-20 22:16:06.898 16088-16088 / com.webview.ak.webviewapp I / chromium:[INFO:library_loader_hooks.cc(144)]启用Chromium日志记录:级别= 0,默认详细程度= 0
08-20 22:16:06.898 16088-16088 / com.webview.ak.webviewapp I / cr_LibraryLoader:预期的本地库版本号59.0.3071.125,实际本机库版本号59.0.3071.125
08-20 22:16:06.914 16088-16088 / com.webview.ak.webviewapp I / cr_BrowserStartup:初始化铬进程,singleProcess = true
08-20 22: 16:06.933 16088-16088 / com.webview.ak.webviewapp我/ Adreno:QUALCOMM构建:01d2d27,I3d52eaf367
构建日期:12/10/16
OpenGL ES Shader编译器版本:XE031.09.00.03
本地分支:
远程分支:
远程分支:
重建分支:
08-20 22:16: 07.011 16088-16203 / com.webview.ak.webviewapp W / cr_BindingManager:无法setInForeground() - 从未看到pid的连接:16088
08-20 22:16:07.028 16088-16088 / com.webview。 ak.webviewapp D / EgretLoader:EgretLoader(上下文环境)
08-20 22:16:07.030 16088-16088 / com.webview.ak.webviewapp D / EgretLoader:上下文不是活动
08- 20 22:16:07.039 16088-16207 / com.webview.ak.webviewapp W / cr_media:需要BLUETOOTH权限
08-20 22 :16:07.076 16088-16088 / com.webview.ak.webviewapp E / HAL:PATH3 /odm/lib64/hw/gralloc.qcom.so
08-20 22:16:07.076 16088-16088 / com。 webview.ak.webviewapp E / HAL:PATH2 /vendor/lib64/hw/gralloc.qcom.so
08-20 22:16:07.076 16088-16088 / com.webview.ak.webviewapp E / HAL:PATH1 /system/lib64/hw/gralloc.qcom.so
08-20 22:16:07.076 16088-16088 / com.webview.ak.webviewapp E / HAL:PATH3 /odm/lib64/hw/gralloc.msm8953 .so
08-20 22:16:07.076 16088-16088 / com.webview.ak.webviewapp E / HAL:PATH2 /vendor/lib64/hw/gralloc.msm8953.so
08-20 22 :16:07.076 16088-16088 / com.webview.ak.webviewapp E / HAL:PATH1 /system/lib64/hw/gralloc.msm8953.so
08-20 22:16:07.076 16088-16223 / com。 webview.ak.webviewapp E / libEGL:validate_display:99 error 3008(EGL_BAD_DISPLAY)
08-20 22:16:07.092 16088-16088 / com.webview.ak.webviewapp D / ActivityThreadInjector:clearCachedDrawables。
08-20 22:16:07.123 16088-16223 / com.webview.ak.webviewapp W / VideoCapabilities:无法识别的配置文件2130706433 for video / avc
08-20 22:16:07.123 16088-16223 / com.webview.ak.webviewapp W / VideoCapabilities:无法识别的配置文件2130706434 for video / avc
08-20 22:16:07.128 16088-16223 / com.webview.ak.webviewapp W / Utils:无法解析长范围'175-174'
08-20 22:16:07.131 16088-16223 / com.webview.ak.webviewapp W / VideoCapabilities:无法识别的配置文件2130706433 for video / avc
08-20 22:16: 07.131 16088-16223 / com.webview.ak.webviewapp W / VideoCapabilities:无法识别的配置文件2130706434 for video / avc
08-20 22:16:07.132 16088-16223 / com.webview.ak.webviewapp W / VideoCapabilities:无法识别的配置文件2130706433 for video / avc
08-20 22:16:07.132 16088-16223 / com.webview.ak.webviewapp W / VideoCapabilities:无法识别的配置文件2130706434 for video / avc
08-20 22: 16:07.134 16088-16223 / com.webview.ak.webviewapp W / VideoCapabilities:无法识别的配置文件/级别0/3 for video / mpeg2
08-20 22:16:07.136 16088-16223 / com.webview.ak.webviewapp W / VideoCapabilities:视频/ mpeg2无法识别的配置文件/级别0/3
08-20 22 :16:07.141 16088-16221 / com.webview.ak.webviewapp I / OpenGLRenderer:初始化EGL,版本1.4
08-20 22:16:07.141 16088-16221 / com.webview.ak.webviewapp D / OpenGLRenderer :交换行为1
08-20 22:16:07.151 16088-16223 / com.webview.ak.webviewapp W / VideoCapabilities:不支持的mime视频/ mp4v-esdp
08-20 22:16:07.164 16088-16205 / com.webview.ak.webviewapp D / NetworkSecurityConfig:未指定Network Security Config,使用平台默认值
08-20 22:16:07.171 16088-16223 / com.webview.ak.webviewapp I / VideoCapabilities :视频/ mp4v-es不支持的配置文件4
08-20 22:16:07.377 16088-16088 / com.webview.ak.webviewapp W / cr_BindingManager:无法调用determineVisibility() - 从未看到pid的连接:16088
08-20 22:16:09.777 16088-16088 / com.webview.ak.webviewapp V / BoostFramework:BoostFramework():m Perf = com.qualcomm.qti.Performance@beb206
08-20 22:17:19.259 16088-16203 / com.webview.ak.webviewapp W / cr_BindingManager:无法setInForeground() - 从未看到pid的连接:16088


解决方案

您可以使用Chrome自定义标签
阅读 here。


什么是Chrome自定义标签?



当用户点击一个URL来启动浏览器或构建他们自己的应用内浏览器使用WebViews。

这两个选项都带来挑战 - 启动浏览器是一种非定制的沉重上下文切换,而WebViews不共享状态Chrome浏览器自定义标签可以让应用程序更好地控制他们的网络体验,并且可以在本地和网络内容之间进行转换。



无需借助WebView便可无缝连接。



Chrome自定义标签可让应用定制Chrome的外观和感觉。应用程序可以改变以下内容:

工具栏颜色



输入并退出动画



为Chrome工具栏,溢出菜单和底部工具栏添加自定义操作

从支持中添加: / p>

依赖关系{... compile'c​​om.android.support:customtabs:23.3.0'}



示例:

字符串网址=¨https://google.com/¨; CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); CustomTabsIntent customTabsIntent = builder.build(); customTabsIntent.launchUrl(this,Uri.parse(url));



更新可以转换 webview 上的html5,方法如下:

  wv = (WebView)findViewById(R.id.webview); 
WebSettings ws = wv.getSettings();
ws.setJavaScriptEnabled(true);
ws.setAllowFileAccess(true);
if(Build.VERSION.SDK_INT> = Build.VERSION_CODES.ECLAIR){
try {
Log.d(TAG,启用HTML5-Features);
方法m1 = WebSettings.class.getMethod(setDomStorageEnabled,new Class [] {Boolean.TYPE});
m1.invoke(ws,Boolean.TRUE);方法m2 = WebSettings.class.getMethod(setDatabaseEnabled,new Class [] {Boolean.TYPE});
m2.invoke(ws,Boolean.TRUE);
方法m3 = WebSettings.class.getMethod(setDatabasePath,new Class [] {String.class});
m3.invoke(ws,/ data / data /+ getPackageName()+/ databases /);
方法m4 = WebSettings.class.getMethod(setAppCacheMaxSize,new Class [] {Long.TYPE});
m4.invoke(ws,1024 * 1024 * 8);
方法m5 = WebSettings.class.getMethod(setAppCachePath,new Class [] {String.class});
m5.invoke(ws,/ data / data /+ getPackageName()+/ cache /);
方法m6 = WebSettings.class.getMethod(setAppCacheEnabled,new Class [] {Boolean.TYPE});
m6.invoke(ws,Boolean.TRUE); Log.d(标记,启用HTML5特性);
} catch(NoSuchMethodException e){
Log.e(TAG,Reflection fail,e);
} catch(InvocationTargetException e){
Log.e(TAG,Reflection fail,e);
} catch(IllegalAccessException e){
Log.e(TAG,Reflection fail,e);
}
}


I'm trying to build a simple app with a webview which opens my html page with an . The html page opens the camera when loaded using a browser on my phone, but does not open the camera in my webview. I have tried searching for answers but i'm not really sure about the actual issue. Can someone please help me understand what is wrong. I am pasting the code and logcat output below.

Mainactivity:

    package com.webview.ak.webviewapp;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.webkit.JavascriptInterface;
import android.webkit.PermissionRequest;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    final String TAG = "MainActivity";
    //final String LOCAL_FILE ="http://10.0.2.2/Beacon/newcam.php";
    final String LOCAL_FILE ="http://192.168.1.35/Beacon/newcam.php";

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


        // Find the web view in our layout xml
        WebView myWebView = (WebView) findViewById(R.id.webview);


        // Settings
        WebSettings webSettings = myWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setDomStorageEnabled(true);
        webSettings.setAllowFileAccessFromFileURLs(true);
        webSettings.setAllowUniversalAccessFromFileURLs(true);
        webSettings.setAllowContentAccess(true);
        webSettings.setDisplayZoomControls(true);

        // Set a web view client and a chrome client
        myWebView.setWebViewClient(new WebViewClient());
        myWebView.setWebChromeClient(new WebChromeClient() {
            // Need to accept permissions to use the camera and audio
            @TargetApi(Build.VERSION_CODES.M)

            @Override
            public void onPermissionRequest(final PermissionRequest request) {
                Log.d(TAG, "onPermissionRequest");

                        // Make sure the request is coming from our file
                        // Warning: This check may fail for local files
                            request.grant(request.getResources());



            }
        });



        // Load the local HTML file into the webview
        myWebView.loadUrl(LOCAL_FILE);
    }



}

xml file:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">


    <WebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />
</RelativeLayout>

Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.webview.ak.webviewapp">
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

    <uses-feature android:name="android.hardware.camera" android:required="true" />
    <uses-feature android:name="android.hardware.camera.front" android:required="true" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        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>

HTML File:

<html>
<head>

</head>

<body>
<input type="file" accept="image/*">

</body>
</html>

Logcat output:

08-20 22:16:06.590 16088-16088/? I/art: Late-enabling -Xcheck:jni
08-20 22:16:06.599 16088-16088/? D/TidaProvider: TidaProvider()
08-20 22:16:06.606 16088-16088/? V/BoostFramework: mAcquireFunc method = public int com.qualcomm.qti.Performance.perfLockAcquire(int,int[])
08-20 22:16:06.606 16088-16088/? V/BoostFramework: mReleaseFunc method = public int com.qualcomm.qti.Performance.perfLockRelease()
08-20 22:16:06.606 16088-16088/? V/BoostFramework: mAcquireTouchFunc method = public int com.qualcomm.qti.Performance.perfLockAcquireTouch(android.view.MotionEvent,android.util.DisplayMetrics,int,int[])
08-20 22:16:06.607 16088-16088/? V/BoostFramework: mIOPStart method = public int com.qualcomm.qti.Performance.perfIOPrefetchStart(int,java.lang.String)
08-20 22:16:06.607 16088-16088/? V/BoostFramework: mIOPStop method = public int com.qualcomm.qti.Performance.perfIOPrefetchStop()
08-20 22:16:06.619 16088-16088/? V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@e7557a
08-20 22:16:06.653 16088-16088/com.webview.ak.webviewapp W/System: ClassLoader referenced unknown path: /data/app/com.webview.ak.webviewapp-2/lib/arm64
08-20 22:16:06.690 16088-16088/com.webview.ak.webviewapp W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
08-20 22:16:06.721 16088-16088/com.webview.ak.webviewapp V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@1a0cdff
08-20 22:16:06.722 16088-16088/com.webview.ak.webviewapp V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@27597cc
08-20 22:16:06.793 16088-16088/com.webview.ak.webviewapp I/WebViewFactory: Loading com.android.chrome version 59.0.3071.125 (code 307112552)
08-20 22:16:06.883 16088-16088/com.webview.ak.webviewapp I/cr_LibraryLoader: Time to load native libraries: 5 ms (timestamps 1900-1905)
08-20 22:16:06.898 16088-16088/com.webview.ak.webviewapp I/chromium: [INFO:library_loader_hooks.cc(144)] Chromium logging enabled: level = 0, default verbosity = 0
08-20 22:16:06.898 16088-16088/com.webview.ak.webviewapp I/cr_LibraryLoader: Expected native library version number "59.0.3071.125", actual native library version number "59.0.3071.125"
08-20 22:16:06.914 16088-16088/com.webview.ak.webviewapp I/cr_BrowserStartup: Initializing chromium process, singleProcess=true
08-20 22:16:06.933 16088-16088/com.webview.ak.webviewapp I/Adreno: QUALCOMM build                   : 01d2d27, I3d52eaf367
                                                                   Build Date                       : 12/10/16
                                                                   OpenGL ES Shader Compiler Version: XE031.09.00.03
                                                                   Local Branch                     : 
                                                                   Remote Branch                    : 
                                                                   Remote Branch                    : 
                                                                   Reconstruct Branch               : 
08-20 22:16:07.011 16088-16203/com.webview.ak.webviewapp W/cr_BindingManager: Cannot setInForeground() - never saw a connection for the pid: 16088
08-20 22:16:07.028 16088-16088/com.webview.ak.webviewapp D/EgretLoader: EgretLoader(Context context)
08-20 22:16:07.030 16088-16088/com.webview.ak.webviewapp D/EgretLoader: The context is not activity
08-20 22:16:07.039 16088-16207/com.webview.ak.webviewapp W/cr_media: Requires BLUETOOTH permission
08-20 22:16:07.076 16088-16088/com.webview.ak.webviewapp E/HAL: PATH3 /odm/lib64/hw/gralloc.qcom.so
08-20 22:16:07.076 16088-16088/com.webview.ak.webviewapp E/HAL: PATH2 /vendor/lib64/hw/gralloc.qcom.so
08-20 22:16:07.076 16088-16088/com.webview.ak.webviewapp E/HAL: PATH1 /system/lib64/hw/gralloc.qcom.so
08-20 22:16:07.076 16088-16088/com.webview.ak.webviewapp E/HAL: PATH3 /odm/lib64/hw/gralloc.msm8953.so
08-20 22:16:07.076 16088-16088/com.webview.ak.webviewapp E/HAL: PATH2 /vendor/lib64/hw/gralloc.msm8953.so
08-20 22:16:07.076 16088-16088/com.webview.ak.webviewapp E/HAL: PATH1 /system/lib64/hw/gralloc.msm8953.so
08-20 22:16:07.076 16088-16223/com.webview.ak.webviewapp E/libEGL: validate_display:99 error 3008 (EGL_BAD_DISPLAY)
08-20 22:16:07.092 16088-16088/com.webview.ak.webviewapp D/ActivityThreadInjector: clearCachedDrawables.
08-20 22:16:07.123 16088-16223/com.webview.ak.webviewapp W/VideoCapabilities: Unrecognized profile 2130706433 for video/avc
08-20 22:16:07.123 16088-16223/com.webview.ak.webviewapp W/VideoCapabilities: Unrecognized profile 2130706434 for video/avc
08-20 22:16:07.128 16088-16223/com.webview.ak.webviewapp W/Utils: could not parse long range '175-174'
08-20 22:16:07.131 16088-16223/com.webview.ak.webviewapp W/VideoCapabilities: Unrecognized profile 2130706433 for video/avc
08-20 22:16:07.131 16088-16223/com.webview.ak.webviewapp W/VideoCapabilities: Unrecognized profile 2130706434 for video/avc
08-20 22:16:07.132 16088-16223/com.webview.ak.webviewapp W/VideoCapabilities: Unrecognized profile 2130706433 for video/avc
08-20 22:16:07.132 16088-16223/com.webview.ak.webviewapp W/VideoCapabilities: Unrecognized profile 2130706434 for video/avc
08-20 22:16:07.134 16088-16223/com.webview.ak.webviewapp W/VideoCapabilities: Unrecognized profile/level 0/3 for video/mpeg2
08-20 22:16:07.136 16088-16223/com.webview.ak.webviewapp W/VideoCapabilities: Unrecognized profile/level 0/3 for video/mpeg2
08-20 22:16:07.141 16088-16221/com.webview.ak.webviewapp I/OpenGLRenderer: Initialized EGL, version 1.4
08-20 22:16:07.141 16088-16221/com.webview.ak.webviewapp D/OpenGLRenderer: Swap behavior 1
08-20 22:16:07.151 16088-16223/com.webview.ak.webviewapp W/VideoCapabilities: Unsupported mime video/mp4v-esdp
08-20 22:16:07.164 16088-16205/com.webview.ak.webviewapp D/NetworkSecurityConfig: No Network Security Config specified, using platform default
08-20 22:16:07.171 16088-16223/com.webview.ak.webviewapp I/VideoCapabilities: Unsupported profile 4 for video/mp4v-es
08-20 22:16:07.377 16088-16088/com.webview.ak.webviewapp W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 16088
08-20 22:16:09.777 16088-16088/com.webview.ak.webviewapp V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@beb206
08-20 22:17:19.259 16088-16203/com.webview.ak.webviewapp W/cr_BindingManager: Cannot setInForeground() - never saw a connection for the pid: 16088

解决方案

You can use Chrome custom tabs Read about it here.

What are Chrome Custom Tabs?

App developers face a choice when a user taps a URL to either launch a browser, or build their own in-app browser using WebViews.

Both options present challenges — launching the browser is a heavy context switch that isn't customizable, while WebViews don't share state with the browser and add maintenance overhead.

Chrome Custom Tabs give apps more control over their web experience, and make transitions between native and web content more seamless without having to resort to a WebView.

Chrome Custom Tabs allow an app to customize how Chrome looks and feels. An app can change things like:

Toolbar color

Enter and exit animations

Add custom actions to the Chrome toolbar, overflow menu and bottom toolbar

Add it from support :

dependencies { ... compile 'com.android.support:customtabs:23.3.0' }

Example :

String url = ¨https://google.com/¨; CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); CustomTabsIntent customTabsIntent = builder.build(); customTabsIntent.launchUrl(this, Uri.parse(url));

Update Also you can turn html5 on webview by turning following settings on:

 wv = (WebView) findViewById(R.id.webview);
 WebSettings ws = wv.getSettings();
 ws.setJavaScriptEnabled(true);
 ws.setAllowFileAccess(true); 
if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.ECLAIR) { 
try { 
Log.d(TAG, "Enabling HTML5-Features"); 
Method m1 = WebSettings.class.getMethod("setDomStorageEnabled", new Class[]{Boolean.TYPE});
  m1.invoke(ws, Boolean.TRUE); Method m2 = WebSettings.class.getMethod("setDatabaseEnabled", new Class[]{Boolean.TYPE}); 
m2.invoke(ws, Boolean.TRUE); 
Method m3 = WebSettings.class.getMethod("setDatabasePath", new Class[]{String.class}); 
m3.invoke(ws, "/data/data/" + getPackageName() + "/databases/");
  Method m4 = WebSettings.class.getMethod("setAppCacheMaxSize", new Class[]{Long.TYPE}); 
m4.invoke(ws, 1024*1024*8); 
Method m5 = WebSettings.class.getMethod("setAppCachePath", new Class[]{String.class}); 
m5.invoke(ws, "/data/data/" + getPackageName() + "/cache/"); 
Method m6 = WebSettings.class.getMethod("setAppCacheEnabled", new Class[]{Boolean.TYPE}); 
 m6.invoke(ws, Boolean.TRUE); Log.d(TAG, "Enabled HTML5-Features"); 
} catch (NoSuchMethodException e) {
  Log.e(TAG, "Reflection fail", e); 
} catch (InvocationTargetException e) {
 Log.e(TAG, "Reflection fail", e);
 } catch (IllegalAccessException e) {
 Log.e(TAG, "Reflection fail", e); 
}
 }

这篇关于Webview中的摄像头支持HTML输入标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆