I'd like to create a Github repository that will contain only PDF files. For fetching PDF files I will use retrofit in a way described at this link:
https://futurestud.io/tutorials/retrofit-2-how-to-download-files-from-server
So right now I just wanted to list all the files from one of my Android projects on Github. (right now it only contains one PDF file)
This is the implementation:
Network module:
private static final String BASE_URL = "https://github.com/username/repository/";
@Provides
@Singleton
Retrofit provideRetrofit(RxJavaCallAdapterFactory rxJavaCallAdapterFactory, Gson gsonConverterFactory) {
return new Retrofit.Builder()
.baseUrl(BASE_URL)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.addConverterFactory(GsonConverterFactory.create(gsonConverterFactory))
.build();
}
Retrofit service:
@Streaming
@GET(".")
Call<List<okhttp3.ResponseBody>> getFiles();
And inside my activity, I'm trying to fetch the files:
Call<List<okhttp3.ResponseBody>> call = retrofitService.getFiles();
call.enqueue(new Callback<List<okhttp3.ResponseBody>>() {
@Override
public void onResponse(@NonNull Call<List<okhttp3.ResponseBody>> call, @NonNull Response<List<okhttp3.ResponseBody>> response) {
if (response.body() != null) {
Toast.makeText(HomeScreenActivity.this, response.message(), Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(@NonNull Call<List<okhttp3.ResponseBody>> call, @NonNull Throwable t) {
Toast.makeText(HomeScreenActivity.this, t.getMessage(), Toast.LENGTH_SHORT).show();
}
});
And when I run it, I get "Expected BEGIN_ARRAY but was STRING at line 7 column 1 path $" error in onFailure() method.
After that I tried this way (without List):
@Streaming
@GET(".")
Call<okhttp3.ResponseBody> getFiles();
And inside Activity:
Call<okhttp3.ResponseBody> call = retrofitService.getFiles();
call.enqueue(new Callback<okhttp3.ResponseBody>() {
@Override
public void onResponse(@NonNull Call<okhttp3.ResponseBody> call, @NonNull Response<okhttp3.ResponseBody> response) {
if (response.body() != null) {
Toast.makeText(HomeScreenActivity.this, response.message(), Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(@NonNull Call<okhttp3.ResponseBody> call, @NonNull Throwable t) {
Toast.makeText(HomeScreenActivity.this, t.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
And the onResponse is called and the response is just this:
Response{
protocol=http/1.1,
code=200,
message=OK,
url=https: //github.com/username/repository/
}
Is this way of fetching PDF files even possible? If it is, can you tell me if something is not right with my implementation?