How to make a request from an extension?

Hi everyone,
I am trying to launch a GET request (later also a POST) from an extension I am making. I found this extension:

I decided to try and yeet some of the code used there but I am getting errors:

AndroidRuntime:
    [mkdir] Created dir: G:\Daten\appinventor-sources-master\src\appinventor\components\build\classes\AndroidRuntime
    [javac] Compiling 318 source files to G:\Daten\appinventor-sources-master\src\appinventor\components\build\classes\AndroidRuntime
    [javac] warning: [options] bootstrap class path not set in conjunction with -source 7
    [javac] warning: [options] source value 7 is obsolete and will be removed in a future release
    [javac] warning: [options] target value 7 is obsolete and will be removed in a future release
    [javac] warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
    [javac] warning: In component CryptoAPI, method SendGetRequests is missing a description.
    [javac] Note: Wrote file file:///G:/Daten/appinventor-sources-master/src/appinventor/components/build/classes/AndroidRuntime/simple_components.json
    [javac] warning: In component CryptoAPI, method SendGetRequests is missing a description.
    [javac] Note: Wrote file file:///G:/Daten/appinventor-sources-master/src/appinventor/components/build/classes/AndroidRuntime/simple_components.txt
    [javac] Note: Wrote file file:///G:/Daten/appinventor-sources-master/src/appinventor/components/build/classes/AndroidRuntime/simple_components_build_info.json
    [javac] warning: In component CryptoAPI, method SendGetRequests is missing a description.
    [javac] Note: Wrote file file:///G:/Daten/appinventor-sources-master/src/appinventor/components/build/classes/AndroidRuntime/AutogeneratedOdeMessages.java
    [javac] Note: Wrote file file:///G:/Daten/appinventor-sources-master/src/appinventor/components/build/classes/AndroidRuntime/ComponentsTranslation.java
    [javac] warning: In component CryptoAPI, method SendGetRequests is missing a description.
    [javac] G:\Daten\appinventor-sources-master\src\appinventor\components\src\io\sproup\CryptoAPI.java:10: error: package com.android.volley.toolbox does not exist
    [javac] import com.android.volley.toolbox.StringRequest;
    [javac]                                  ^
    [javac] G:\Daten\appinventor-sources-master\src\appinventor\components\src\io\sproup\CryptoAPI.java:11: error: package com.android.volley.toolbox does not exist
    [javac] import com.android.volley.toolbox.Volley;
    [javac]                                  ^
    [javac] G:\Daten\appinventor-sources-master\src\appinventor\components\src\io\sproup\CryptoAPI.java:9: error: package com.android.volley does not exist
    [javac] import com.android.volley.*;
    [javac] ^
    [javac] Note: Some input files use or override a deprecated API.
    [javac] Note: Recompile with -Xlint:deprecation for details.
    [javac] 3 errors
    [javac] 8 warnings

This is the request code:

@SimpleFunction(description = "Test")
    public void SendGetRequests(String url){
      RequestQueue queue= Volley.newRequestQueue(context);
      StringRequest stringRequest=new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
         Get(response);
  
        }
      }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
          Error(error.getMessage());
        }
      });
  
      queue.add(stringRequest);
    }

And those are my imports:

import com.google.appinventor.components.annotations.*;
import com.google.appinventor.components.runtime.*;
import com.google.appinventor.components.common.*;

import android.content.Context;
import com.android.volley.*;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;

import java.util.HashMap;
import java.util.Map;

And ideas how I can fix that? I don’t know where volley would be.

https://community.kodular.io/t/curl-to-blocks-convert-curl-request-to-blocks/153467/17

1 Like

Site not found.

Would the page output the code needed? It sounds like it would just give blocks which is not what I need. In any case, thank you!

1 Like

It can be used as Get method.

You can see the source of my baserow extension for some examples.

3 Likes

The source code you are using is missing the popular Android HTTP library Volley.
See examples here by Vknow to make a POST request:

1 Like