mirror of
https://github.com/pppscn/SmsForwarder
synced 2025-08-03 01:17:41 +08:00
修复:在子线程中调用Toast的异常情况处理
This commit is contained in:
parent
b0465eec54
commit
43f33e5fe2
@ -1,5 +1,6 @@
|
|||||||
package com.idormy.sms.forwarder.utils.sender
|
package com.idormy.sms.forwarder.utils.sender
|
||||||
|
|
||||||
|
import android.os.Looper
|
||||||
import android.text.TextUtils
|
import android.text.TextUtils
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
@ -104,7 +105,9 @@ class TelegramUtils {
|
|||||||
override fun onFailure(call: Call, e: IOException) {
|
override fun onFailure(call: Call, e: IOException) {
|
||||||
SendUtils.updateLogs(logId, 0, e.message.toString())
|
SendUtils.updateLogs(logId, 0, e.message.toString())
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
//XToastUtils.error("发送失败:" + e.message)
|
Looper.prepare()
|
||||||
|
XToastUtils.error("发送失败:" + e.message)
|
||||||
|
Looper.loop()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
@ -115,10 +118,14 @@ class TelegramUtils {
|
|||||||
val resp = Gson().fromJson(responseStr, TelegramResult::class.java)
|
val resp = Gson().fromJson(responseStr, TelegramResult::class.java)
|
||||||
if (resp.ok == true) {
|
if (resp.ok == true) {
|
||||||
SendUtils.updateLogs(logId, 2, responseStr.toString())
|
SendUtils.updateLogs(logId, 2, responseStr.toString())
|
||||||
|
Looper.prepare()
|
||||||
XToastUtils.success(ResUtils.getString(R.string.request_succeeded))
|
XToastUtils.success(ResUtils.getString(R.string.request_succeeded))
|
||||||
|
Looper.loop()
|
||||||
} else {
|
} else {
|
||||||
SendUtils.updateLogs(logId, 0, responseStr.toString())
|
SendUtils.updateLogs(logId, 0, responseStr.toString())
|
||||||
|
Looper.prepare()
|
||||||
XToastUtils.error(ResUtils.getString(R.string.request_failed) + response)
|
XToastUtils.error(ResUtils.getString(R.string.request_failed) + response)
|
||||||
|
Looper.loop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.idormy.sms.forwarder.utils.sender
|
package com.idormy.sms.forwarder.utils.sender
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
|
import android.os.Looper
|
||||||
import android.text.TextUtils
|
import android.text.TextUtils
|
||||||
import android.util.Base64
|
import android.util.Base64
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
@ -164,7 +165,10 @@ class WebhookUtils {
|
|||||||
override fun onFailure(call: Call, e: IOException) {
|
override fun onFailure(call: Call, e: IOException) {
|
||||||
SendUtils.updateLogs(logId, 0, e.message.toString())
|
SendUtils.updateLogs(logId, 0, e.message.toString())
|
||||||
//LogUtils.updateLog(logId, 0, e.message)
|
//LogUtils.updateLog(logId, 0, e.message)
|
||||||
|
//解决在子线程中调用Toast的异常情况处理
|
||||||
|
Looper.prepare()
|
||||||
XToastUtils.error(ResUtils.getString(R.string.request_failed) + e.message)
|
XToastUtils.error(ResUtils.getString(R.string.request_failed) + e.message)
|
||||||
|
Looper.loop()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
@ -172,14 +176,17 @@ class WebhookUtils {
|
|||||||
val responseStr = response.body().toString()
|
val responseStr = response.body().toString()
|
||||||
Log.d(TAG, "Response:" + response.code() + "," + responseStr)
|
Log.d(TAG, "Response:" + response.code() + "," + responseStr)
|
||||||
|
|
||||||
|
|
||||||
//返回http状态200即为成功
|
//返回http状态200即为成功
|
||||||
if (200 == response.code()) {
|
if (200 == response.code()) {
|
||||||
SendUtils.updateLogs(logId, 2, responseStr)
|
SendUtils.updateLogs(logId, 2, responseStr)
|
||||||
|
Looper.prepare()
|
||||||
XToastUtils.success(ResUtils.getString(R.string.request_succeeded))
|
XToastUtils.success(ResUtils.getString(R.string.request_succeeded))
|
||||||
|
Looper.loop()
|
||||||
} else {
|
} else {
|
||||||
SendUtils.updateLogs(logId, 0, responseStr)
|
SendUtils.updateLogs(logId, 0, responseStr)
|
||||||
|
Looper.prepare()
|
||||||
XToastUtils.error(ResUtils.getString(R.string.request_failed) + response)
|
XToastUtils.error(ResUtils.getString(R.string.request_failed) + response)
|
||||||
|
Looper.loop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user