How do I make an extension that retrieves the source code of a web page?

this can do the same thing too, so I think we don't need an extension for that @Meulencv

blocks (3)

3 Likes

Still, it's okay for learning :wink:

3 Likes

But I ned to do this, to later do the extension more complex, for example a extension that gives the bitcoin price.

Hello,
I would be very grateful if you could fix my code, thank you very much :slightly_smiling_face:

@Meulencv did you fixed that?

1 Like

I have the demo extension code which works.

Demo code

File name: Request.java

package com.kumaraswamy.request;

import android.app.Activity;
import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.SimpleEvent;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.EventDispatcher;
import com.google.appinventor.components.runtime.util.AsynchUtil;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;

@DesignerComponent(version = 1,
        category = ComponentCategory.EXTENSION,
        description = "Made my YOU",
        nonVisible = true,
        iconName = "ICON LINK")

@SimpleObject(external = true)

public class Request extends AndroidNonvisibleComponent {

    private Activity activity;

    public Request(ComponentContainer container) {
        super(container.$form());
        activity = container.$context();
    }

    @SimpleFunction
    public void DoRequest(final String website) {
        AsynchUtil.runAsynchronously(new Runnable() {
            @Override
            public void run() {
                BufferedReader in;
                try {
                    in = new BufferedReader(
                            new InputStreamReader(
                                    new URL(website).openStream()));

                    String inputLine;
                    final StringBuilder result = new StringBuilder();

                    while ((inputLine = in.readLine()) != null)
                        result.append(inputLine);

                    in.close();

                    activity.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            GotResult(result.toString());
                        }
                    });
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    @SimpleEvent
    public void GotResult(String result) {
        EventDispatcher.dispatchEvent(this, "GotResult", result);
    }
}
8 Likes

Thank you very much with all my heart @Kumaraswamy , I don't know how to thank you. IT WORKS! :grin: :grin: :grin:

1 Like

used your code and got compile error in kodular

    Kodular is unable to compile this project.
The compiler error output was
________Preparing application icon
________Creating animation xml
________Creating fragment xml
________Creating listview xml in res/layout/..
________Creating listview xml in res/layout-v21/..
________Creating xml in res/drawable/..
________Creating splash png in res/drawable/..
________Creating colors xml
________Creating styles xml
________Creating drawables xml v21
________Checking for firebase
________Creating provider_path xml
________Creating network_security_config xml
________Generating adaptive icon file
________Generating round adaptive icon file
________Generating adaptive icon background file
________Generating manifest file
________Attaching native libraries
________Attaching Android Archive (AAR) libraries
________Attaching component assets
________Invoking AAPT
AAPT time: 1.217 seconds
________Compiling source files
.
1 Like

I'm solving the problem

I have solved the problem, thank you very much for the warning. :grinning:

It's not the fault of the extension, I have compiled the code over two times...

1 Like

Extensions. I added this extension to an empty project and it hasn't compiled anymore.

1 Like

Hi, it compiles correctly for me and the app works on the mobile. Have you tried v2 of the extension?

1 Like

Can you tell us what changes did you make in the source code which @Kumaraswamy provided?

1 Like

It do like web scrapping,
When the extension get the source of the web page, it cut a part of the source to get the value like (btc price)

so i think it can be made without having to use extension?

1 Like

Yes, but is more simple to use the extension

:cough:

2 Likes

yeah I think you are right, but it's also simple without having to use extensions. :grin:
And I've done it > Click this <

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.