How to use WEB component in extension function

Hi,

I want to create an extension that would send and fetch json data.
You pass url and Post parameters to it, it would fetch data and process it and return data in json format indicating “SUCCESS”/“FAIL”.
However Im stuck at a point as to

  1. how to use the WEB component in my function,
  2. How to pass URL and PostText To it.
  3. And lastly how to capture the data from GotText event.

My function looks as :

@SimpleFunction
public void sendData(String url,String dataToSend){
//How i declare WEB component here <==
this.url = url;
this.dataToSend = dataToSend;

//is this correct way to pass the data ?
this.web.Url(this.url);
this.web.PostText(this.dataToSend);

//how to capture data received by the WEB component and raise your own event with output
}

see the App Inventor sources, in your case the web component

Taifun

1 Like

Just make an object of the web component that is available in the AI sources like this

Web web = new Web() ;

This will create a new web component and will assign in the web variable and you can use that to post the text this way
web. PostText(text_to_post) ;

And you are good to go

1 Like
1 Like

Thank you Sumit bhai.

How can i capture the data received (GotText event)?

You can use When any Got Text event of any web component and you can also invoke the Got Text event in your extension

1 Like

Thanks.

I meant that supposed i have declared.:

Web web = new Web;
web. PostText(text_to_post) ;

where or how do capture the GotText event ?
thanks

This wont work. It’s wrong.

2 Likes

Just Ovveride a call back after posting the text like this

    @Override void GotText(...) {
    // your text
} 

And you are all done

Thanks alot sumit bhai.

Let me try it.

1 Like

Thanks Xoma.

check this -

Thanks Aarush Kumar.

Its almost same concept as i wanted except i want to receive data not a file.
How do i do it ?
Please send code on how to capture the GotText Event with code, if you are able to.
Thanks.