android - Camera support in Webview for HTML input tag -
i'm trying build simple app webview opens html page . html page opens camera when loaded using browser on phone, not open camera in webview. have tried searching answers i'm not sure actual issue. can please me understand wrong. pasting code , 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 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 web view client , chrome client mywebview.setwebviewclient(new webviewclient()); mywebview.setwebchromeclient(new webchromeclient() { // need accept permissions use camera , audio @targetapi(build.version_codes.m) @override public void onpermissionrequest(final permissionrequest request) { log.d(tag, "onpermissionrequest"); // make sure request coming our file // warning: check may fail local files request.grant(request.getresources()); } }); // load local html file 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) have incorrectly overridden 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 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 connection 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: context 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 video/avc 08-20 22:16:07.123 16088-16223/com.webview.ak.webviewapp w/videocapabilities: unrecognized profile 2130706434 video/avc 08-20 22:16:07.128 16088-16223/com.webview.ak.webviewapp w/utils: not parse long range '175-174' 08-20 22:16:07.131 16088-16223/com.webview.ak.webviewapp w/videocapabilities: unrecognized profile 2130706433 video/avc 08-20 22:16:07.131 16088-16223/com.webview.ak.webviewapp w/videocapabilities: unrecognized profile 2130706434 video/avc 08-20 22:16:07.132 16088-16223/com.webview.ak.webviewapp w/videocapabilities: unrecognized profile 2130706433 video/avc 08-20 22:16:07.132 16088-16223/com.webview.ak.webviewapp w/videocapabilities: unrecognized profile 2130706434 video/avc 08-20 22:16:07.134 16088-16223/com.webview.ak.webviewapp w/videocapabilities: unrecognized profile/level 0/3 video/mpeg2 08-20 22:16:07.136 16088-16223/com.webview.ak.webviewapp w/videocapabilities: unrecognized profile/level 0/3 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 video/mp4v-es 08-20 22:16:07.377 16088-16088/com.webview.ak.webviewapp w/cr_bindingmanager: cannot call determinedvisibility() - never saw connection 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 connection pid: 16088
you can use chrome custom tabs read here.
what chrome custom tabs?
app developers face choice when user taps url either launch browser, or build own in-app browser using webviews.
both options present challenges — launching browser heavy context switch isn't customizable, while webviews don't share state browser , add maintenance overhead.
chrome custom tabs give apps more control on web experience, , make transitions between native , web content more seamless without having resort webview.
chrome custom tabs allow app customize how chrome looks , feels. app can change things like:
toolbar color
enter , exit animations
add custom actions chrome toolbar, overflow menu , bottom toolbar
add 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 can turn html5 on webview
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); } }
Comments
Post a Comment