How To Do This In Java

Better check Web component’s source.

@iamwsumit i get this error

Error

Started Compiling Project WebPost
Buildfile: /compiler/androidX/build.xml

javac:
[mkdir] Created dir: /compiler/androidX/build/wLzMc/classes
[javac] Compiling 1 source file to /compiler/androidX/build/wLzMc/classes
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] Note: Wrote file file:/compiler/androidX/build/wLzMc/classes/simple_components.json
[javac] Note: Wrote file file:/compiler/androidX/build/wLzMc/classes/simple_components.txt
[javac] Note: Wrote file file:/compiler/androidX/build/wLzMc/classes/simple_components_build_info.json
[javac] Note: Wrote file file:/compiler/androidX/build/wLzMc/classes/AutogeneratedOdeMessages.java
[javac] Note: Wrote file file:/compiler/androidX/build/wLzMc/classes/ComponentsTranslation.java
[javac] /compiler/androidX/src/wLzMc/com/web/post/WebPost.java:54: error: cannot find symbol
[javac] Data(bufferedReader.readLine()) ;
[javac] ^
[javac] symbol: method Data(String)
[javac] location: class WebPost
[javac] 1 error

My Code


import android.app.Activity;
import android.content.Context;
import com.google.appinventor.components.annotations.*;
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 java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;


@DesignerComponent(
        version = 1,
        description = "",
        category = ComponentCategory.EXTENSION,
        nonVisible = true,
        iconName = "")

@SimpleObject(external = true)
//Libraries
@UsesLibraries(libraries = "")
//Permissions
@UsesPermissions(permissionNames = "")

public class WebPost extends AndroidNonvisibleComponent {

    //Activity and Context
    private Context context;
    private Activity activity;

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

    @SimpleFunction(description = "b")
   public void run() {
            try {
          URL obj = new URL("https://www.google.com");
      HttpURLConnection httpConnection = (HttpURLConnection)obj.openConnection();
      httpConnection.setDoOutput(true); //if you want output
      httpConnection.setRequestMethod("POST"); //request method
      BufferedReader bufferedReader = null;
      if (httpConnection.getResponseCode() == 200) {
        bufferedReader = new BufferedReader(new InputStreamReader(httpConnection.getInputStream()));
        
      } else {
        bufferedReader = new BufferedReader(new InputStreamReader(httpConnection.getErrorStream()));
      } 
      StringBuilder content = new StringBuilder();
      String line;
      while ((line = bufferedReader.readLine()) != null){
        content.append(line).append("\n"); 
        Data(bufferedReader.readLine()) ;
      }
      bufferedReader.close();
      final String con = String.valueOf(content); //post wherever you need
      
    }
    catch(Exception e){
    e.printStackTrace();
    }
   }
   @SimpleEvent(description = "Generated Store Url")
    public void WebPost(String Data) {
      EventDispatcher.dispatchEvent(this, "AllOrders", Data);
      }
}

So What Should I Do @iamwsumit

i imported into koudlar but empty result

@iamwsumit What Should I Do Know

You also need to use thread

i tried but can you show a example i didn’t not understand @Sumit1334

What you have tried in thread? Show me.

Haven’t I already posted?

There are a lot of open source extension. Also web component is Open Source. Why don’t you search a little? Google the thread and you will get your answer.

Just run it on non-ui or other thread!

AsynchUtil.runAsynchronously(new Runnable() {
            @Override
            public void run() {
                // YOUR WORK
            }
        });
new Thread(new Runnable() {
            @Override
            public void run() {
                // YOUR WORK
            }
        }).start();
ExecutorService executorService = Executors.newSingleThreadExecutor();
        executorService.execute(new Runnable() {
            @Override
            public void run() {
                    // YOUR WORK
            }
        });

Anyone of this is okay!

@Xoma
@iamwsumit
My Code


import android.app.Activity;
import android.content.Context;
import com.google.appinventor.components.annotations.*;
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 java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;


@DesignerComponent(
        version = 1,
        description = "",
        category = ComponentCategory.EXTENSION,
        nonVisible = true,
        iconName = "")

@SimpleObject(external = true)
//Libraries
@UsesLibraries(libraries = "")
//Permissions
@UsesPermissions(permissionNames = "")

public class WebPost extends AndroidNonvisibleComponent {

    //Activity and Context
    private Context context;
    private Activity activity;

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

   
    AsynchUtil.runAsynchronously(new Runnable() {
            @Override
            public void run() {
                 @SimpleFunction(description = "b")
   public void run() {
            try {
          URL obj = new URL("https://www.google.com");
      HttpURLConnection httpConnection = (HttpURLConnection)obj.openConnection();
      httpConnection.setDoOutput(true); //if you want output
      httpConnection.setRequestMethod("POST"); //request method
      BufferedReader bufferedReader = null;
      if (httpConnection.getResponseCode() == 200) {
        bufferedReader = new BufferedReader(new InputStreamReader(httpConnection.getInputStream()));
        
      } else {
        bufferedReader = new BufferedReader(new InputStreamReader(httpConnection.getErrorStream()));
      } 
      StringBuilder content = new StringBuilder();
      String line;
      while ((line = bufferedReader.readLine()) != null){
        content.append(line).append("\n"); 
        Data(bufferedReader.readLine()) ;
      }
      bufferedReader.close();
      final String con = String.valueOf(content); //post wherever you need
      
    }
    catch(Exception e){
    e.printStackTrace();
    }
            }
        });
   }
   @SimpleEvent(description = "Generated Store Url")
    public void WebPost(String Data) {
      EventDispatcher.dispatchEvent(this, "AllOrders", Data);
      }
}

You are just blindly doing things.
Learn the basics.