如何解决此问题? 我不知道解决方法。 检查我的代码并帮助我。
请忽略:看来您的帖子大部分是代码;请添加更多详细信息。看起来您的帖子大部分是代码;请添加更多详细信息。看起来您的帖子大部分是代码;请添加更多详细信息。看起来您的帖子大部分是代码;请添加更多详细信息。看起来您的帖子大部分是代码;请添加更多详细信息。看起来您的帖子大部分是代码;请添加更多详细信息。看起来您的帖子大部分是代码;请添加更多详细信息。看起来您的帖子大部分是代码;请添加更多详细信息。看起来您的帖子大部分是代码;请添加更多详细信息。看起来您的帖子大部分是代码;请添加更多详细信息。
class Informationactivity : AppCompatactivity() {
private val _tag = Splashactivity::class.java.simpleName
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_information)
val uniqueId = SharedPreference.getidInfo(this)
val token = SharedPreference.getUserInfo(this)
Client.retrofitService.profile(uniqueId,token)
.enqueue(object : Callback<LoginResponse> {
override fun onFailure(call: Call<LoginResponse>,t: Throwable) {
}
override fun onResponse(
call: Call<LoginResponse>,response: Response<LoginResponse>
) {
if (response?.isSuccessful == false) { val er = Gson().fromJson(response.errorBody()?.charStream(),ErrorResponse::class.java)
Log.d(_tag,"${er.code}:${er.message}")
if (er.code == 60203) {
Toast.makeText(this@Informationactivity,"",Toast.LENGTH_SHORT).show()
}
} else if (response?.isSuccessful == true) {
Glide.with(applicationContext).asBitmap().load("https://s3.amazonaws.com/appsdeveloperblog/micky.gif").into(imageView)
Toast.makeText(this@Informationactivity,Toast.LENGTH_LONG).show()
val file=File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),"micky.gif")
var fileName="micky.gif"
val token = SharedPreference.getUserInfo(applicationContext)
val uniqueId= SharedPreference.getidInfo(applicationContext)
var requestBody: RequestBody = RequestBody.create(MediaType.parse("image/*"),file)
val body: MultipartBody.Part = MultipartBody.Part.createFormData("profile",fileName,requestBody)
if (uniqueId != null) {
Client.retrofitService.updateProfile(token,uniqueId,body)
.enqueue(object : Callback<List<LoginResponse>> {
override fun onFailure(
call: Call<List<LoginResponse>>,t: Throwable) { Log.d("",t.message) }
override fun onResponse(
call: Call<List<LoginResponse>>,response: Response<List<LoginResponse>>) { if (response?.isSuccessful)
{ Toast.makeText(this@Informationactivity,"File Uploaded Successfully...",Toast.LENGTH_LONG).show()
Log.d("","" + response?.body().toString())
} else {
Toast.makeText(this@Informationactivity,"Some error occurred...",Toast.LENGTH_LONG).show()
}
} }) }
}
}
}) }
}
interface API {
@Headers("Content-Type: application/json","Authorization:token:String")
@Multipart
@PUT("/user/profile/{userId}")
fun updateProfile(@Header("Authorization") token: String?,@Path("userId") userID: String,@Part file: MultipartBody.Part): Call<List<Loginresponse>>
}
object Client {
var retrofitService: API
init {
val interceptor = HttpLoggingInterceptor()
interceptor.level = HttpLoggingInterceptor.Level.BODY
val logger: OkHttpClient = OkHttpClient.Builder().addInterceptor(interceptor).readTimeout(20,TimeUnit.SECONDS).writeTimeout(20,TimeUnit.SECONDS).build()
val retrofit = Retrofit.Builder()
.baseUrl("myurl")
.addConverterFactory(GsonConverterFactory.create())
.client(logger)
.build()
retrofitService = retrofit.create(API::class.java)
}
}
@SerializedName("uniqueId")
val user:String?=null
@SerializedName("nickname")
val nickname: String?=null
@SerializedName("birth")
val birth: String?=null
@SerializedName("profileImage")
val profileImage: String?=null
@SerializedName("profileThumbnail")
val profileThumbnails: String?=null
@SerializedName("gender")
val gender: Int?=null
@SerializedName("token")
val token: String? = null
}