1

I want to pull asynchronous json data with retrofit and rxjava 3 in the foreground service and show it to the user as a notification, but so far I have not been successful.

@Streaming
@GET("v2/top-headlines")
fun getDayNewsRxJava(
    @Query("country") language : String,
    @Query("apiKey") key : String
) : Observable<Model1>

val retrofit = Retrofit.Builder()
        .baseUrl("https://newsapi.org/")
        .addCallAdapterFactory(RxJava3CallAdapterFactory.create())
        .addConverterFactory(GsonConverterFactory.create())
        .build()

fun returnEveryDay() : everydayNews {
    return retrofit.create(everydayNews::class.java)
}

newsRetrofit.returnEveryDay().getDayNewsRxJava("language" , "apiKey")
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(object : Observer<Model1> {
            override fun onSubscribe(d: Disposable?) {
            }
            override fun onNext(t: Model1?) {
                val title = t!!.articles[0].title
                Log.d(TAG , "Rx Java Data : ${t?.articles[0].title}")
                sendNotification(title)
            }

            override fun onError(e: Throwable?) {
                Log.e(TAG , "Rx Java Error : $e")
            }

            override fun onComplete() {
                Log.d(TAG , "Rx Java Completed")
            }

        })

I looked at different examples in this way, they did not use a very different structure, but I do not understand why an asynchronous call is not made.

thanks for your help

Mert Krgl
  • 11
  • 1
  • 1

0 Answers0