Home
This is the wiki, here you can find everything about ProWebView.
Here you can find an example about how to use ProWebView and the API reference.
First of all you need to add this permission to the manifest:
<uses-permission android:name="android.permission.INTERNET" />
Create a layout like this:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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="vcm.github.webkit.prowebview.MainActivity">
<vcm.github.webkit.proview.ProWebView
android:id="@+id/webview"
app:cacheMode="cacheElseNetwork"
app:locationEnabled="true"
app:javascriptEnabled="true"
app:locationMode="modeFine"
app:nestedScrollingEnabled="true"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
And set the onCreate(Bundle savedInstanceState)
:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ProWebView webView = (ProWebView) findViewById(R.id.webview);
webView.setActivity(this); // Also works with fragments!
webView.loadUrl("http://www.google.com/");
}
Don't forget to override the following methods:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
webView.onActivityResult(requestCode, resultCode, data);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
webView.onRestoreInstanceState(savedInstanceState);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
webView.onRequestPermissionResult(requestCode, permissions, grantResults);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
webView.onSavedInstanceState(outState);
}
@Override
protected void onDestroy() {
super.onDestroy();
webView.onDestroy();
}
Add this to your layout:
<vcm.github.webkit.proview.ProWebViewControls
android:id="@+id/controls"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
And add this to the onCreate(Bundle savedInstanceState)
:
ProWebViewControls controls = (ProWebViewControls) findViewById(R.id.controls);
controls.setProWebView(webView);
Just call loadHtml(String)
or any other variant:
webView.loadHtml("your html code here");
Just call loadMarkdown(String)
:
webView.loadMarkdown("your markdown code here");
Just add the following permissions to your manifest and ProWebView will do all the rest:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
If you want to listen for the events you have to set a ProClient
:
webView.setProClient(new ProWebView.ProClient() {
@Override
public void onProgressChanged(ProWebView webView, int progress) {
}
@Override
public void onStateChanged(ProWebView webView) {
}
@Override
public void onWindowStateChanged(ProWebView webView, boolean showing) {
}
@Override
public void onInformationReceived(ProWebView webView, String url, String title, Bitmap favicon) {
}
@Override
public void onCustomViewStateChanged(ProWebView webView, View customView, boolean showing) {
}
@Override
public void onDownloadStarted(ProWebView webView, String filename, String url) {
}
@Override
public void onReceivedError(ProWebView webView, ProWebResourceRequest resourceRequest, ProWebResourceError webResourceError) {
}
});
ProWebView can handle and request the permissions bi itself. You can handle those actions and ask the user:
webView.setPermissionCallback(new ProWebView.PermissionCallback() {
@Override
public void onPermissionRequested(ProWebView.RequestCallback<String[]> callback, String[] permission) {
}
@Override
public void onGeolocationPermission(ProWebView.RequestCallback<Boolean> callback) {
}
});
Note: this actions requires to add the following permissions in your manifest:
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
If you want to print the content of ProWebView you can use this wraper:
webView.printWebView(new ProWebView.PrintListener() {
@Override
public void onSuccess() {
}
@Override
public void onFailed() {
}
});
Lets say you want to open an app that can handle a potato://
scheme. You have to do this:
webView.addSpecialScheme("potato", new ProWebView.SchemeRequest() {
@Override
public boolean onSchemeRequested(ProWebView view, String url) {
//Do whatever you want
return true; //Must return true
}
});
Knowing this you can play with ProWebView and check out all the functionalities.