Professional Documents
Culture Documents
Apiconnecton Retrofit KT
Apiconnecton Retrofit KT
---------------------
<uses-permission android:name="android.permission.INTERNET" />
android:usesCleartextTraffic="true"
gradle---
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
MainActivity---------
------------------------
class MainActivity : AppCompatActivity() {
val op = "Tecxpert@MP#123\$456%789^"
val appName = "com.tecxpert.saras_pro"
val appVersion = "33"
val appUserCode = "arjun"
val appUserPwd = "a"
val UserID = "arjun"
val Pwd = "a"
var yourDataMode: ArrayList<lovingItem> = ArrayList()
private val apiServiceManager = ApiServiceManager()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
fetchData()
}
private fun fetchData() {
val call: Call<YourDataModel> = apiServiceManager.fetchDataFromApi(op,
appName, appVersion, appUserCode, appUserPwd,UserID,Pwd)
call.enqueue(object : Callback<YourDataModel> {
override fun onResponse(call: Call<YourDataModel>, response:
Response<YourDataModel>) {
if (response.isSuccessful) {
val dataItem = response.body()
yourDataMode =java.util.ArrayList<lovingItem>()
yourDataMode = dataItem?.loving as
java.util.ArrayList<lovingItem>
if (yourDataMode != null) {
Toast.makeText(
applicationContext, "data save succesfully",
Toast.LENGTH_LONG
).show()
}
// Handle the data here
} else {
// Handle the error
}
}
Model class----
-------------------
data class YourDataModel (
@field:SerializedName("LoginData")
val loving: List<lovingItem?>? = null
)
data class lovingItem(
@field:SerializedName("MCC_Code")
val MCC_Code: String? = null,
@field:SerializedName("MCC_NAME")
val MCC_NAME: String? = null,
@field:SerializedName("Mcc_Code_VLC_Uploader")
val Mcc_Code_VLC_Uploader: String? = null,
@field:SerializedName("User_APP_Type")
val User_APP_Type: String? = null,
@field:SerializedName("Vendor_Code")
val Vendor_Code: String? = null,
@field:SerializedName("VLC_Code_VLC_Uploader")
val VLC_Code_VLC_Uploader: String? = null,
@field:SerializedName("Vendor_Name")
val Vendor_Name: String? = null,
@field:SerializedName("Current_UserCode")
val Current_UserCode: String? = null,
@field:SerializedName("Current_UserName")
val Current_UserName: String? = null,
@field:SerializedName("MP_Code")
val MP_Code: String? = null,
@field:SerializedName("MP_Code_VLC_Uploader")
val MP_Code_VLC_Uploader: String? = null,
@field:SerializedName("MP_Name")
val MP_Name: String? = null,
@field:SerializedName("Result")
val Result: String? = null,