make a webview with a static local webpage, via "datauri"

This commit is contained in:
Alexander Mahr 2024-10-08 12:00:10 +02:00
parent 3a9ac9f73f
commit 1a1b53aaa6

View file

@ -8,26 +8,22 @@ 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;
public class ExampleApp extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// creating LinearLayout
LinearLayout linLayout = new LinearLayout(this);
// specifying vertical orientation
linLayout.setOrientation(LinearLayout.VERTICAL);
// creating LayoutParams
LayoutParams linLayoutParam = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
// set LinearLayout as a root element of the screen
setContentView(linLayout, linLayoutParam);
LayoutParams lpView = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
TextView tv = new TextView(this);
tv.setText("SUPERVIEalexW");
tv.setLayoutParams(lpView);
linLayout.addView(tv);
WebView myWebView = new WebView(this);//activityContext);
WebViewClient myWebViewClient= new WebViewClient();
myWebView.setWebViewClient(myWebViewClient);
String unencodedHtml = "<!DOCTYPE html><html><h1> this is html <h1> <h2> this is a h2</h2></html>";
String encodedHtml = Base64.encodeToString(unencodedHtml.getBytes(),Base64.NO_PADDING);
myWebView.loadData(encodedHtml, "text/html", "base64");
//myWebView.loadUrl("https://alexmahr.de/ru");
setContentView(myWebView);
}
}