0

I want to return data via retrofit , this is the json from my api

{
"peyks": [{
    "name": "\u0627\u062a\u0646\u0627\u0644",
    "vasile": "\u067e\u06cc\u06a9 \u0645\u0648\u062a\u0648\u0631\u06cc",
    "address": "\u0646\u062a\u0644\u0628\u0627\u0644\u062f\u062a\u0644\u0644\u062a",
    "date": "1397-11-25  09:50:54",
    "tel": "00000000000"
}, {
    "name": "\u0627\u062a\u0646",
    "vasile": "\u067e\u06cc\u06a9 \u0645\u0648\u062a\u0648\u0631\u06cc",
    "address": "\u062a\u0627\u0627\u0644\u0644\u0628\u0633",
    "date": "1397-11-24  18:20:16",
    "tel": "00000000000"
}]
}

I'm coding with json, this is my connection class :

object ApiConnection {
val BaseUrl ="http://site.ir/"
val client: Retrofit
    get() {
        val gson = GsonBuilder()
            .setLenient()
            .create()

        ///for Logging
        val interceptor = HttpLoggingInterceptor()
        interceptor.level = HttpLoggingInterceptor.Level.BODY
        val client = OkHttpClient.Builder().addInterceptor(interceptor).build()


        var retrofit = Retrofit.Builder()
            .baseUrl(BaseUrl)
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .addConverterFactory(GsonConverterFactory.create(gson))
            .client(client)
            .build()
        return retrofit
    }

}

These are the model classes :

    data class Peyk_item(
        val address: String,
        val date: String,
        val name: String,
        val tel: String,
        val vasile: String
)

    data class Peyks(
        val peyks: List<Peyk_item>
)

This is my interface class :

    interface getPeykHistoryApi {
    @FormUrlEncoded
    @POST("getPeykList.php")
    fun getPeykHistory(@Field("uid")uid:String): Single<Peyks>
}

This is the activity class code

 val get:getPeykHistoryApi=ApiConnection.client.create(getPeykHistoryApi::class.java)
    get.getPeykHistory(Func.getUid(this))
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe({ result ->

            }, { error ->
                MyToast.makeText(this@PeykHistory, "2 error " +error.localizedMessage.toString());
            })

The manifest is ok , it has internet permission

When I run the app , it works fine in emulator and return the data and it works fine in my phone with android 6 but it doesn't work on two phones with android oreo (8)

It doesn't goes into error section , it goes to result but the response is null .

what is wrong ?

Vivek Mishra
  • 5,669
  • 9
  • 46
  • 84
Navid Abutorab
  • 1,667
  • 7
  • 31
  • 58

1 Answers1

0

Try this it may be helpful to solve your problem because of network security you have to add this in the application tag.

AndroidManifest.xml

<application
    ...
    android:usesCleartextTraffic="true">
</application>

Nilesh Panchal
  • 1,059
  • 1
  • 10
  • 24