diff --git a/apk/src/app/example/ExampleApp.java b/apk/src/app/example/ExampleApp.java index 073d095..7e41bbe 100644 --- a/apk/src/app/example/ExampleApp.java +++ b/apk/src/app/example/ExampleApp.java @@ -13,14 +13,41 @@ import android.widget.*; //import android.widget.TextView; import android.webkit.*; import android.net.Uri; +import org.json.JSONObject; //import android.webkit.WebView; //import android.webkit.WebMessage; //import android.webkit.WebMessagePort; - +import java.io.InputStream; public class ExampleApp extends Activity { private static final String BASE_URI = "https://alexmahr.de"; + private WebMessagePort port; + private void initPort(WebView myWebView) { + final WebMessagePort[] channel=myWebView.createWebMessageChannel(); + port=channel[0]; + port.setWebMessageCallback(new WebMessagePort.WebMessageCallback() { + @Override + public void onMessage(WebMessagePort port, WebMessage message) { + } + }); + myWebView.postWebMessage(new WebMessage("", new WebMessagePort[]{channel[1]}),Uri.parse(BASE_URI)); + } + + public String readFileFromAssets(String filename) { + String filecontents = ""; + try { + InputStream stream = getAssets().open(filename); + int filesize = stream.available(); + byte[] filebuffer = new byte[filesize]; + stream.read(filebuffer); + stream.close(); + filecontents = new String(filebuffer); + } catch (Exception e) { + // I <3 java exceptions + } + return filecontents; + } @Override public void onCreate(Bundle savedInstanceState) { @@ -39,17 +66,19 @@ public class ExampleApp extends Activity { myWebSettings.setDisplayZoomControls(false); myWebSettings.setJavaScriptEnabled(true); myWebView.addJavascriptInterface(this, "myJavaScriptInterface"); - // providing a webpage inline - String unencodedHtml = "https://html5test.co/