1

I have an url similar to http://www.myexample.com/rss/choose.php?type=level&id=2 and I want to use Retrofit in my android app. The problem is that type is a parameter which can take different values like level, grade, etc. I can't adapt Retrofit every time type change because I get a "Annotations are not allowed here" in TestesInterface. I was looking to this post and applied to my app but it doesn't work.

static final String BASE_URL = "http://www.myexample.com/rss/";

public void start() {
    Retrofit retrofit = new Retrofit.Builder().baseUrl(BASE_URL)
            .addConverterFactory(SimpleXmlConverterFactory.create()).build();

    TestesInterface testesInterface = retrofit.create(TestesInterface.class);

    Call<Channel> call = testesInterface.loadChannel("choose.php?type=level&id=2");
    call.enqueue(this);
}

My interface:

public interface TestesInterface {
    @GET
    Call<Channel> loadChannel(@Url type);
}

This made that every time I want to change type to a different value I should change testesInterface.loadChannel("choose.php?type=level&id=2"). This doesn't work. Can you please help me?

Dima Kozhevin
  • 3,602
  • 9
  • 39
  • 52
porthfind
  • 1,581
  • 3
  • 17
  • 30

1 Answers1

0

After try different approaches I got the solution. I had to use the tag @Query to type and id on interface and send the values when I'm invoking it in start():

@GET
Call<Channel> loadChannel(@Query("type") String type,
                          @Query("id") String value);
porthfind
  • 1,581
  • 3
  • 17
  • 30