non-working because JavasBrigde <> Webview thread
This commit is contained in:
parent
8785107ea5
commit
1c4c210091
3 changed files with 9 additions and 34 deletions
|
@ -18,11 +18,11 @@ public class ExampleApp extends Activity {
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
MyJavascriptInterface myJavaScriptInterface = new MyJavascriptInterface(this);
|
|
||||||
// this removes the title bar (a ~1cm big strip at the top of the app showing its name
|
// this removes the title bar (a ~1cm big strip at the top of the app showing its name
|
||||||
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
// we create the webview (at least on the android 14 that is a webview that features avif + websockets etc....)
|
// we create the webview (at least on the android 14 that is a webview that features avif + websockets etc....)
|
||||||
WebView myWebView = new WebView(this);//activityContext);
|
WebView myWebView = new WebView(this);//activityContext);
|
||||||
|
MyJavascriptInterface myJavaScriptInterface = new MyJavascriptInterface(this,myWebView);
|
||||||
// we create a webview (there is also setwebviewclient-vs-setwebchromeclient
|
// we create a webview (there is also setwebviewclient-vs-setwebchromeclient
|
||||||
WebViewClient myWebViewClient= new WebViewClient();
|
WebViewClient myWebViewClient= new WebViewClient();
|
||||||
myWebView.setWebViewClient(myWebViewClient);
|
myWebView.setWebViewClient(myWebViewClient);
|
||||||
|
@ -39,7 +39,7 @@ public class ExampleApp extends Activity {
|
||||||
// alternatively this could be to load a website
|
// alternatively this could be to load a website
|
||||||
//myWebView.loadUrl("https://alexmahr.de/ru");
|
//myWebView.loadUrl("https://alexmahr.de/ru");
|
||||||
setContentView(myWebView);
|
setContentView(myWebView);
|
||||||
new java.util.Timer().schedule( new MyRunnable(myWebView),2000);
|
// new java.util.Timer().schedule( new MyRunnable(myWebView),2000);
|
||||||
// java.util.TimerTask() {
|
// java.util.TimerTask() {
|
||||||
// @Override
|
// @Override
|
||||||
// public void run() {
|
// public void run() {
|
||||||
|
|
|
@ -18,9 +18,11 @@ import java.io.*;
|
||||||
|
|
||||||
public class MyJavascriptInterface {
|
public class MyJavascriptInterface {
|
||||||
private Activity activity;
|
private Activity activity;
|
||||||
|
private WebView webview;
|
||||||
|
|
||||||
public MyJavascriptInterface(Activity activity) {
|
public MyJavascriptInterface(Activity activity,WebView webview) {
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
|
this.webview = webview;;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @JavascriptInterface
|
// @JavascriptInterface
|
||||||
|
@ -30,5 +32,8 @@ public class MyJavascriptInterface {
|
||||||
// activity.startActivity(intent);
|
// activity.startActivity(intent);
|
||||||
// }
|
// }
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
public String toString() { return "injectedObject"; }
|
public String toString() {
|
||||||
|
this.webview.evaluateJavascript("(setTimeout(()=>{document.body.innerHTML='all gone';},2000)()",null);
|
||||||
|
return "injectedobject";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,30 +0,0 @@
|
||||||
|
|
||||||
package app.example;
|
|
||||||
|
|
||||||
import android.util.Log;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.text.method.ScrollingMovementMethod;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.*;
|
|
||||||
import android.widget.*;
|
|
||||||
import android.webkit.WebView;
|
|
||||||
import android.webkit.*;
|
|
||||||
import android.view.ViewGroup.*;
|
|
||||||
import android.util.Base64;
|
|
||||||
import java.util.Timer;
|
|
||||||
import java.util.TimerTask;
|
|
||||||
|
|
||||||
public class MyRunnable extends TimerTask
|
|
||||||
{
|
|
||||||
WebView InnerWebView;
|
|
||||||
public MyRunnable(WebView MyWebView){
|
|
||||||
InnerWebView=MyWebView;
|
|
||||||
}
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
InnerWebView.evaluateJavascript("document.body.innerHTML='all is lost';",null);
|
|
||||||
System.out.println( "Now is " );
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue