✨ [Free] NoFileHtml - view html without files

Sure, sending u the file

Ahh I can't DM you can u please DM :slightly_smiling_face:

1 Like

Done sent you a message.

1 Like

The solution here is to remove any/all html comments

<!-- ... -->

and javascript comments

// comment

from the html, and to use the NoFileHtml extension.

For some reason, the text block does not handle these well causing the webviewer to try to parse them as either html or javascript.

1 Like

Yeah right, Thanks for your support @TIMAI2 :hugs:

I like this extension Tim! Great job!

I required this so thanks :smiley:

25 posts were split to a new topic: Google Search with NoFileHtml extension

A post was merged into an existing topic: Google Search with NoFileHtml extension

It works on Android 11!!! :blush: Thank You!!!

1 Like

not working can you please check

player.html.txt (9.0 KB)

Remove all your comments, e.g. // play, from your javascript, then try again.

See

✨ [Free] NoFileHtml - view html without files - #16 by TIMAI2

(I have now updated the first post with this information)

2 Likes

can i have its code

Sure:

package uk.co.metricrat.nofilehtml;

import android.util.*;
import android.webkit.*;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.runtime.*;
import java.io.*;
import java.io.File;

import static org.acra.ACRA.LOG_TAG;

public class NoFileHtml extends AndroidNonvisibleComponent {

  public NoFileHtml(ComponentContainer container) {

    super(container.$form());
  }
  private String filePath;

  @SimpleFunction(description = "presents html text in a webviewer")
  public void NoFileHtml(String html, WebViewer webViewer) {

    //give webviewer file access for Kodular users
    WebView webView = (WebView)webViewer.getView();
    webView.getSettings().setAllowFileAccess(true);
    webView.getSettings().setAllowFileAccessFromFileURLs(true);
    webView.getSettings().setAllowUniversalAccessFromFileURLs(true);
    webView.getSettings().setAllowContentAccess(true);

    //create html file
    try {
      java.io.File file = File.createTempFile("display", ".html");
      filePath = file.getAbsolutePath();
      FileWriter filewriter = new FileWriter(file);
      filewriter.write(html);
      filewriter.close();
      file.deleteOnExit();
    } catch (IOException e) {
      Log.e(LOG_TAG, "IOException", e);
    }
    //show html
    webViewer.GoToUrl("file://" + filePath);


  }





}
1 Like

building extension from https://ide.niotron.com/ gives error

It's a Rush project. To compile it from the Niotron IDE you need to add required annotations.

@DesignerComponent
@SimpleObject

oh ok

Great extension! Thanks!

Improved Security in NoFileHtml:
- Old: Used temporary files and deprecated WebView permissions (setAllowFileAccess, setAllowFileAccessFromFileURLs).
+ New: Direct HTML rendering using loadDataWithBaseURL with minimal WebView settings. Removed all file operations.
Goal: Prevent security vulnerabilities while maintaining full HTML rendering functionality.
package uk.co.metricrat.nofilehtml;

import android.util.Log;
import android.webkit.WebView;
import android.webkit.WebSettings;
import android.webkit.WebViewClient;
import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.WebViewer;

@DesignerComponent(
    version = 2,
    description = "Renders HTML content directly in a WebViewer without using temporary files",
    nonVisible = true,
    iconName = "icon.png"
)
public class NoFileHtml extends AndroidNonvisibleComponent {
    
    public NoFileHtml(ComponentContainer container) {
        super(container.$form());
    }
    
    @SimpleFunction(description = "Renders HTML content safely in a WebViewer")
    public void NoFileHtml(String string, WebViewer webViewer) {
        try {
            final WebView webView = (WebView) webViewer.getView();
            
            // Configuração mínima necessária
            WebSettings settings = webView.getSettings();
            settings.setJavaScriptEnabled(true);
            
            // Configura um WebViewClient básico para melhor controle
            webView.setWebViewClient(new WebViewClient());
            
            // Carrega o conteúdo diretamente
            webView.loadDataWithBaseURL(
                null,                                    // baseUrl
                string,                                  // data
                "text/html; charset=UTF-8",             // mimeType
                "UTF-8",                                // encoding
                null                                    // historyUrl
            );
            
        } catch (Exception e) {
            Log.e("NoFileHtml", "Error rendering HTML content", e);
        }
    }
}
4 Likes

Nice revision @Passos_0213 :tada:

I compiled an aix (on RUSH) for others to test:

uk.co.metricrat.nofilehtmlV2.aix (4.6 KB)

(may/may not work on Kodular ?)

1 Like

I think it will be because this version doesn't save the html file anywhere, instead it loads the page directly from the String.

2 Likes

Done some testing.

In general works as expected, and can pull in resources (e.g. images / files etc) from online urls, shared directories, ASD, and assets.

Seems to be able to handle html comments, e.g. <!--comment-->, but still, as with V1, not coping with javascript comments e.g. //comment, inside script tags

Gets a :+1: from me.

Now set as the default extension in the first post

1 Like

Maybe it works with \/\/comment or adjust the code to escape those characters.