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
|
||||
public void onCreate(Bundle 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.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
// 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);
|
||||
MyJavascriptInterface myJavaScriptInterface = new MyJavascriptInterface(this,myWebView);
|
||||
// we create a webview (there is also setwebviewclient-vs-setwebchromeclient
|
||||
WebViewClient myWebViewClient= new WebViewClient();
|
||||
myWebView.setWebViewClient(myWebViewClient);
|
||||
|
@ -39,7 +39,7 @@ public class ExampleApp extends Activity {
|
|||
// alternatively this could be to load a website
|
||||
//myWebView.loadUrl("https://alexmahr.de/ru");
|
||||
setContentView(myWebView);
|
||||
new java.util.Timer().schedule( new MyRunnable(myWebView),2000);
|
||||
// new java.util.Timer().schedule( new MyRunnable(myWebView),2000);
|
||||
// java.util.TimerTask() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
|
|
|
@ -18,9 +18,11 @@ import java.io.*;
|
|||
|
||||
public class MyJavascriptInterface {
|
||||
private Activity activity;
|
||||
private WebView webview;
|
||||
|
||||
public MyJavascriptInterface(Activity activity) {
|
||||
public MyJavascriptInterface(Activity activity,WebView webview) {
|
||||
this.activity = activity;
|
||||
this.webview = webview;;
|
||||
}
|
||||
|
||||
// @JavascriptInterface
|
||||
|
@ -30,5 +32,8 @@ public class MyJavascriptInterface {
|
|||
// activity.startActivity(intent);
|
||||
// }
|
||||
@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