Answer the question
In order to leave comments, you need to log in
How to manage GET parameters of Retrofit requests?
Well, look.. I want to control the parameters of the get requests that I set in Link.java, but I do not know how to do this.
Code:
MainActivity.java:
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class MainActivity extends AppCompatActivity {
TextView text;
Link link;
String url = "https://mp3go.dev/";
Retrofit retrofit;
String pesni = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text = findViewById(R.id.text);
retrofit = new Retrofit.Builder().baseUrl(url).addConverterFactory(GsonConverterFactory.create()).build();
link = retrofit.create(Link.class);
link.getSongs().enqueue(new Callback<GetSongs>() {
@Override
public void onResponse(Call<GetSongs> call, Response<GetSongs> response) {
List<Song> s = response.body().getResult();
for(int i = 0;i<s.size();i++){
pesni += s.get(i).getTitle()+"\n";
}
text.setText(pesni);
}
@Override
public void onFailure(Call<GetSongs> call, Throwable t) {
text.setText(t.getMessage());
t.printStackTrace();
}
});
}
}
import retrofit2.Call;
import retrofit2.http.GET;
public interface Link {
@GET("api/tracks.searchq=Sting&search_type=&limit=50&offset=100&api_key=997Lsdfsd6iPciVDSsdffsdewR16rewzZYfoofpf1")
Call<GetSongs> getSongs();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question