We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, Pls can any one throw some light on using the webview for android in processing 3.x.
Basically, I want to load a webpage inside my p3 sketch. Pls help.
Thanks in advance.
Answers
https://forum.processing.org/two/discussion/comment/72142/#Comment_72142
Kf
`import android.app.Activity; import android.content.Context; import android.widget.FrameLayout; import android.view.ViewParent; import android.widget.RelativeLayout; import android.text.Editable; import android.graphics.Color; import android.widget.Toast; import android.os.Looper; import android.view.WindowManager; import android.view.inputmethod.InputMethodManager; import android.os.Bundle; import android.os.Environment; import android.view.View; import android.view.ViewGroup; import android.webkit.WebView;
Activity act; FrameLayout fl;
WebView webview;
@Override
public void onStart() { super.onStart();
act = this.getActivity();
webview = new WebView(act); webview.setLayoutParams(new RelativeLayout.LayoutParams( 800, 400 )); webview.setX(800); webview.setY(600); webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("https://processing.org/");
fl = (FrameLayout)act.findViewById(0x1000); fl.addView(webview); }
void settings() { fullScreen(); }
void setup() {
orientation(PORTRAIT); background(255, 0, 0); }
void draw() { }`
Hi @Kfrajer for the reply, however I'm getting an error on this line saying unexpected token : @Override
Not able to understand what I have done wrong. Pls check. Thanks a lot.
@Gpm===
this code works. You are overriding the onStart() method (fragment).
format your code.
put the exact error in the console.
HI @akenaton
Here is the formatted code.
I have taken out override. What I'm seeing is, the page getting opened in a browser after 2 seconds after app launches. Is there a way to control it so, it will be within app window. Thanks again.
once I paste the code, formatting is gone. how I can correct that. :-O
@Gpm===
you can do that using WebViewClient API from android: https://developer.android.com/reference/android/webkit/WebViewClient.html
@Gmp I tried akenaton suggestions and this is how to make it work:
I hope this helps,
Kf
@kfrajer : Thanks a lot. It is working!! :) @akenaton : Thanks for your suggestions. Thanks again.