android - unable to get webview to show video fullscreen -
i have created android application preview website has mp4 video player, works fine im unable preview on full screen when click on video enlarge icon. please note im new , been learning 3 days code mainactivity.java:
import android.app.activity; import android.content.intent; import android.net.uri; import android.os.build; import android.os.environment; import android.os.parcelable; import android.provider.mediastore; import android.os.bundle; import android.support.v7.app.appcompatactivity; import android.util.log; import android.webkit.valuecallback; import android.webkit.webchromeclient; import android.webkit.webview; import android.widget.progressbar; import android.widget.toast; import java.io.file; import java.io.ioexception; public class mainactivity extends appcompatactivity { private webview webview; private progressbar progressbar; // variables camera , choosing files methods private static final int filechooser_resultcode = 1; private valuecallback<uri> muploadmessage; private uri mcapturedimageuri = null; // same android 5.0 methods private valuecallback<uri[]> mfilepathcallback; private string mcameraphotopath; // error handling private static final string tag = mainactivity.class.getsimplename(); @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); // define url open in webview string webviewurl = "http://test.com"; // webview code without handling external links webview = (webview) findviewbyid(r.id.activity_main_webview); webview.getsettings().setjavascriptenabled(true); progressbar = (progressbar) findviewbyid(r.id.progressbar); //webview.getsettings().setusewideviewport(true); //webview.getsettings().setloadwithoverviewmode(true); webview.getsettings().setallowfileaccess(true); // load url in webview webview.loadurl(webviewurl); webview.setwebviewclient(new myappwebviewclient()); // implement webchromeclient inner class // define openfilechooser select file camera webview.setwebchromeclient(new webchromeclient() { // page loading progress, gone when loaded public void onprogresschanged(webview view, int progress) { if (progress < 100 && progressbar.getvisibility() == progressbar.gone) { progressbar.setvisibility(progressbar.visible); } progressbar.setprogress(progress); if (progress == 100) { progressbar.setvisibility(progressbar.gone); } } // lollipop, in 1 public boolean onshowfilechooser( webview webview, valuecallback<uri[]> filepathcallback, webchromeclient.filechooserparams filechooserparams) { if (mfilepathcallback != null) { mfilepathcallback.onreceivevalue(null); } mfilepathcallback = filepathcallback; intent takepictureintent = new intent(mediastore.action_image_capture); if (takepictureintent.resolveactivity(getpackagemanager()) != null) { // create file photo should go file photofile = null; try { photofile = createimagefile(); takepictureintent.putextra("photopath", mcameraphotopath); } catch (ioexception ex) { // error occurred while creating file log.e(tag, "unable create image file", ex); } // continue if file created if (photofile != null) { mcameraphotopath = "file:" + photofile.getabsolutepath(); takepictureintent.putextra(mediastore.extra_output, uri.fromfile(photofile)); } else { takepictureintent = null; } } intent contentselectionintent = new intent(intent.action_get_content); contentselectionintent.addcategory(intent.category_openable); contentselectionintent.settype("image/*"); intent[] intentarray; if (takepictureintent != null) { intentarray = new intent[]{takepictureintent}; } else { intentarray = new intent[0]; } intent chooserintent = new intent(intent.action_chooser); chooserintent.putextra(intent.extra_intent, contentselectionintent); chooserintent.putextra(intent.extra_title, getstring(r.string.image_chooser)); chooserintent.putextra(intent.extra_initial_intents, intentarray); startactivityforresult(chooserintent, filechooser_resultcode); return true; } // creating image files (lollipop only) private file createimagefile() throws ioexception { file imagestoragedir = new file(environment.getexternalstoragepublicdirectory(environment.directory_pictures), "directorynamehere"); if (!imagestoragedir.exists()) { imagestoragedir.mkdirs(); } // create image file name imagestoragedir = new file(imagestoragedir + file.separator + "img_" + string.valueof(system.currenttimemillis()) + ".jpg"); return imagestoragedir; } // openfilechooser android 3.0+ public void openfilechooser(valuecallback<uri> uploadmsg, string accepttype) { muploadmessage = uploadmsg; try { file imagestoragedir = new file(environment.getexternalstoragepublicdirectory(environment.directory_pictures), "directorynamehere"); if (!imagestoragedir.exists()) { imagestoragedir.mkdirs(); } file file = new file(imagestoragedir + file.separator + "img_" + string.valueof(system.currenttimemillis()) + ".jpg"); mcapturedimageuri = uri.fromfile(file); // save private variable final intent captureintent = new intent(android.provider.mediastore.action_image_capture); captureintent.putextra(mediastore.extra_output, mcapturedimageuri); // captureintent.putextra(mediastore.extra_screen_orientation, activityinfo.screen_orientation_portrait); intent = new intent(intent.action_get_content); i.addcategory(intent.category_openable); i.settype("image/*"); intent chooserintent = intent.createchooser(i, getstring(r.string.image_chooser)); chooserintent.putextra(intent.extra_initial_intents, new parcelable[]{captureintent}); startactivityforresult(chooserintent, filechooser_resultcode); } catch (exception e) { toast.maketext(getbasecontext(), "camera exception:" + e, toast.length_long).show(); } } // openfilechooser android < 3.0 public void openfilechooser(valuecallback<uri> uploadmsg) { openfilechooser(uploadmsg, ""); } // openfilechooser other android versions /* may not work on kitkat due lack of implementation of openfilechooser() or onshowfilechooser() https://code.google.com/p/android/issues/detail?id=62220 newer versions of kitkat fixed on devices */ public void openfilechooser(valuecallback<uri> uploadmsg, string accepttype, string capture) { openfilechooser(uploadmsg, accepttype); } }); } // return here when file selected camera or sd card @override public void onactivityresult (int requestcode, int resultcode, intent data) { // code versions except of lollipop if (build.version.sdk_int < build.version_codes.lollipop) { if(requestcode==filechooser_resultcode) { if (null == this.muploadmessage) { return; } uri result=null; try{ if (resultcode != result_ok) { result = null; } else { // retrieve private variable if intent null result = data == null ? mcapturedimageuri : data.getdata(); } } catch(exception e) { toast.maketext(getapplicationcontext(), "activity :"+e, toast.length_long).show(); } muploadmessage.onreceivevalue(result); muploadmessage = null; } } // end of code versions except of lollipop // start of code lollipop if (build.version.sdk_int >= build.version_codes.lollipop) { if (requestcode != filechooser_resultcode || mfilepathcallback == null) { super.onactivityresult(requestcode, resultcode, data); return; } uri[] results = null; // check response 1 if (resultcode == activity.result_ok) { if (data == null || data.getdata() == null) { // if there not data, may have taken photo if (mcameraphotopath != null) { results = new uri[]{uri.parse(mcameraphotopath)}; } } else { string datastring = data.getdatastring(); if (datastring != null) { results = new uri[]{uri.parse(datastring)}; } } } mfilepathcallback.onreceivevalue(results); mfilepathcallback = null; } // end of code lollipop } // handling button @override public void onbackpressed() { if(webview.cangoback()) { webview.goback(); } else { super.onbackpressed(); } } }
and activity_main.xml:
<?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.coordinatorlayout 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" android:fitssystemwindows="true" tools:context="com.test.app.mainactivity"> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/content_main" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <progressbar style="?android:attr/progressbarstylehorizontal" android:id="@+id/progressbar" android:layout_width="match_parent" android:layout_height="wrap_content"/> <webview android:id="@+id/webview1" android:layout_width="match_parent" android:layout_height="match_parent"/> </linearlayout> <android.support.design.widget.appbarlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/apptheme.appbaroverlay"> </android.support.design.widget.appbarlayout> <include layout="@layout/content_main" /> </android.support.design.widget.coordinatorlayout>
how continue code video full screen support
thank in advance
try this:-
in manifest file
<activity android:name="your activity" android:configchanges="keyboardhidden|orientation|screensize" android:theme="@android:style/theme.holo.noactionbar.fullscreen" />
Comments
Post a Comment