Okhttp调用问题

yhm2046 中级 2021-05-11 05:14:06
最近看到android第一行代码第三版746页,按照书上的代码实现没有输入,也没报错,请大师指点谢谢

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val binding = ActivityHttpURLConnectionBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.btnShow.setOnClickListener {
Log.i(TAG,"click btn============")
val response=HttpUtil.sendOkHttpRequest(strURL2,object:Callback{ //此方法调用没有输出也无报错信息
override fun onFailure(call: Call, e: IOException) {
Log.i(TAG,"11111111111111111111111")
e.printStackTrace()
Log.i(TAG,"sendOkHttpRequest Callback err:${e.toString()}")
}

override fun onResponse(call: Call, response: Response) {
Log.i(TAG,"22222222222222222222")
val responseData=response.body?.string() //get value
showResponse(responseData)
}
})
// sendRequestWithOKHttp() //单独的okhttp请求方法
}
}


/**
* 网络操作公共类
*/
object HttpUtil {
private val TAG="HttpUtil_wp"
private val PORT=8000
// OKhttp请求方法,比普通http请求方法简单
fun sendOkHttpRequest(address: String,callback:okhttp3.Callback){
val client=OkHttpClient()
val request=Request.Builder().url(address).build()
client.newCall(request).equals(callback) //内部已经开好子线程,在子线程中执行HTTP请求,结果返回callback
}
...全文
1121 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
莫名的码农 2021-05-19
  • 打赏
  • 举报
回复
网络请求放在主线程了,另起线程吧
ESC尛蜜蜂 2021-05-18
  • 打赏
  • 举报
回复
网络权限加了吗
雕·不懒惰 2021-05-17
  • 打赏
  • 举报
回复
https://blog.csdn.net/weimingjue/article/details/87921494 去看看怎么贴log吧
yhm2046 中级 2021-05-17
  • 打赏
  • 举报
回复
那要什么log,这已经是全部log了
头发还没秃a 2021-05-15
  • 打赏
  • 举报
回复
引用 5 楼 yhm2046 的回复:
log已经贴了
感谢,贴的全是没用的log
yhm2046 中级 2021-05-14
  • 打赏
  • 举报
回复
log已经贴了
yhm2046 中级 2021-05-14
  • 打赏
  • 举报
回复
--------- beginning of main
05-14 09:19:55.731 17447  3586 I NetworkScheduler.Stats: Task com.google.android.gms/com.google.android.gms.fonts.update.UpdateSchedulerService started execution. cause:5 exec_start_elapsed_seconds: 489735 [CONTEXT service_id=218 ]
05-14 09:19:55.733 17447  3586 W FontLog : New version from GServices 20 is less than or equal to current version 20 [CONTEXT service_id=132 ]
05-14 09:19:55.733 17447  3586 I FontLog : Did not start update [CONTEXT service_id=132 ]
05-14 09:19:55.735 17447  2871 I NetworkScheduler.Stats: Task com.google.android.gms/com.google.android.gms.fonts.update.UpdateSchedulerService finished executing. cause:5 result: 1 elapsed_millis: 23 uptime_millis: 23 exec_start_elapsed_seconds: 489735 [CONTEXT service_id=218 ]
05-14 09:19:55.786 17447  2855 I NetworkScheduler.Stats: Task com.google.android.gms/com.google.android.gms.ipa.base.IpaGcmTaskService started execution. cause:5 exec_start_elapsed_seconds: 489735 [CONTEXT service_id=218 ]
05-14 09:19:55.795 21528  4918 I GmscoreIpa: Starting mediastore batch index [CONTEXT service_id=255 ]
05-14 09:19:55.798 17447  2871 I NetworkScheduler.Stats: Task com.google.android.gms/com.google.android.gms.ipa.base.IpaGcmTaskService finished executing. cause:5 result: 1 elapsed_millis: 28 uptime_millis: 28 exec_start_elapsed_seconds: 489735 [CONTEXT service_id=218 ]
05-14 09:19:55.839 21528  4898 I GmscoreIpa: Bulk mediastore status = true [CONTEXT service_id=255 ]
05-14 09:19:55.873 17447  2855 I NetworkScheduler.Stats: Task com.google.android.gms/com.google.android.gms.auth.account.be.accountstate.GcmTaskService started execution. cause:5 exec_start_elapsed_seconds: 489735 [CONTEXT service_id=218 ]
05-14 09:19:55.876 17447  2855 I NetworkScheduler.Stats: Task com.google.android.gms/com.google.android.gms.auth.account.be.accountstate.GcmTaskService finished executing. cause:5 result: 2 elapsed_millis: 25 uptime_millis: 24 exec_start_elapsed_seconds: 489735 [CONTEXT service_id=218 ]
05-14 09:19:55.920 21528  4898 I GmscoreIpa: Batch indexing status=true [CONTEXT service_id=255 ]
05-14 09:19:55.936 17447  2871 I NetworkScheduler.Stats: Task com.google.android.gms/com.google.android.gms.checkin.CheckinService started execution. cause:5 exec_start_elapsed_seconds: 489735 [CONTEXT service_id=218 ]
05-14 09:19:55.941 17447  3586 I NetworkScheduler.Stats: Task com.google.android.gms/com.google.android.gms.checkin.CheckinService finished executing. cause:5 result: 3 elapsed_millis: 26 uptime_millis: 26 exec_start_elapsed_seconds: 489735 [CONTEXT service_id=218 ]
05-14 09:19:56.008 17447  2871 I NetworkScheduler.Stats: Task com.google.android.gms/com.google.android.gms.common.stats.net.NetworkReportService started execution. cause:5 exec_start_elapsed_seconds: 489735 [CONTEXT service_id=218 ]
05-14 09:19:56.014 21528 21528 D BoundBrokerSvc: onBind: Intent { act=com.google.android.gms.common.BIND_SHARED_PREFS pkg=com.google.android.gms }
05-14 09:19:56.014 21528 21528 D BoundBrokerSvc: Loading bound service for intent: Intent { act=com.google.android.gms.common.BIND_SHARED_PREFS pkg=com.google.android.gms }
05-14 09:19:56.019 21528 21528 D BoundBrokerSvc: onUnbind: Intent { act=com.google.android.gms.common.BIND_SHARED_PREFS pkg=com.google.android.gms }
05-14 09:19:56.021  4986  4986 I Finsky:instant_app_inst: [2] hkp.ay(5): Process created at version: 25.2.22-21 [0] [PR] 371378105
05-14 09:19:56.025 21528 21528 D BoundBrokerSvc: onBind: Intent { act=com.google.android.gms.common.BIND_SHARED_PREFS pkg=com.google.android.gms }
05-14 09:19:56.025 21528 21528 D BoundBrokerSvc: Loading bound service for intent: Intent { act=com.google.android.gms.common.BIND_SHARED_PREFS pkg=com.google.android.gms }
05-14 09:19:56.028 21528 21528 D BoundBrokerSvc: onUnbind: Intent { act=com.google.android.gms.common.BIND_SHARED_PREFS pkg=com.google.android.gms }
05-14 09:19:56.056   595   595 I keystore: del USRPKEY_unstable.c7202ece89390c490b1b94d5b71225e1.-8316338568797714801 10018
05-14 09:19:56.057   595   595 I keystore: del USRSKEY_unstable.c7202ece89390c490b1b94d5b71225e1.-8316338568797714801 10018
05-14 09:19:56.057   595   595 I keystore: del USRCERT_unstable.c7202ece89390c490b1b94d5b71225e1.-8316338568797714801 10018
05-14 09:19:56.057   595   595 I keystore: del CACERT_unstable.c7202ece89390c490b1b94d5b71225e1.-8316338568797714801 10018
05-14 09:19:56.061   380   384 D DrmLibTime: got the req here! ret=0
05-14 09:19:56.061   380   384 D DrmLibTime: command id, time_cmd_id = 770
05-14 09:19:56.061   380   384 D DrmLibTime: time_getutcsec starts!
05-14 09:19:56.061   380   384 D DrmLibTime: QSEE Time Listener: time_getutcsec
05-14 09:19:56.061   380   384 D DrmLibTime: QSEE Time Listener: get_utc_seconds
05-14 09:19:56.061   380   384 D DrmLibTime: QSEE Time Listener: time_get_modem_time
05-14 09:19:56.061   380   384 D DrmLibTime: QSEE Time Listener: Checking if ATS_MODEM is set or not.
05-14 09:19:56.061   380   384 D QC-time-services: Lib:time_genoff_operation: pargs->base = 13
05-14 09:19:56.061   380   384 D QC-time-services: Lib:time_genoff_operation: pargs->operation = 2
05-14 09:19:56.061   380   384 D QC-time-services: Lib:time_genoff_operation: pargs->ts_val = 0
05-14 09:19:56.061   380   384 D QC-time-services: Lib:time_genoff_operation: Send to server  passed!!
05-14 09:19:56.062   608   682 D QC-time-services: Daemon: Connection accepted:time_genoff
05-14 09:19:56.064   608  5005 D QC-time-services: Daemon:Received base = 13, unit = 1, operation = 2,value = 0
05-14 09:19:56.064   608  5005 D QC-time-services: Daemon:genoff_opr: Base = 13, val = 0, operation = 2
05-14 09:19:56.064   608  5005 D QC-time-services: offset is: 1 for base: 13
05-14 09:19:56.064   380   384 E QC-time-services: Receive Passed == base = 13, unit = 1, operation = 2, result = 0
05-14 09:19:56.064   380   384 D DrmLibTime: QSEE Time Listener: ATS_MODEM is set. Try to retrieve it.
05-14 09:19:56.065   608   682 E QC-time-services: Daemon: Time-services: Waiting to acceptconnection
05-14 09:19:56.065   608   682 D QC-time-services: Daemon: Connection accepted:time_genoff
05-14 09:19:56.067   608  5006 D QC-time-services: Daemon:Received base = 13, unit = 1, operation = 1,value = 0
05-14 09:19:56.067   608  5006 D QC-time-services: Daemon:genoff_opr: Base = 13, val = 0, operation = 1
05-14 09:19:56.067   608  5006 D QC-time-services: Daemon: genoff get for 13
05-14 09:19:56.067   608  5006 D QC-time-services: Daemon:rtc_get: Time read from RTC -- MM/DD/YY HH:MM:SS1/7/70 11:27:30
05-14 09:19:56.067   608  5006 D QC-time-services: Daemon:Value read from RTC seconds = 3238050000
05-14 09:19:56.067   608  5006 D QC-time-services: Daemon:Value read from generic offset = 1617717142000
05-14 09:19:56.067   608  5006 D QC-time-services: Daemon:Final Time = 1620955192000
05-14 09:19:56.067   380   384 D DrmLibTime: QSEE Time Listener: Time GenOff - seconds: 1620955192
05-14 09:19:56.067   380   384 D DrmLibTime: time_getutcsec returns 0, sec = 1620955192; nsec = 0
05-14 09:19:56.067   380   384 D DrmLibTime: time_getutcsec finished! 
05-14 09:19:56.068   380   384 D DrmLibTime: iotcl_continue_command finished! and return 0 
05-14 09:19:56.068   380   384 D DrmLibTime: before calling ioctl to read the next time_cmd
05-14 09:19:56.068   608   682 E QC-time-services: Daemon: Time-services: Waiting to acceptconnection
05-14 09:19:56.143 25605 25643 I Adreno  : QUALCOMM build                   : 8e59954, I0be83d0d26
05-14 09:19:56.143 25605 25643 I Adreno  : Build Date                       : 09/22/17
05-14 09:19:56.143 25605 25643 I Adreno  : OpenGL ES Shader Compiler Version: EV031.21.02.00
05-14 09:19:56.143 25605 25643 I Adreno  : Local Branch                     : O17A
05-14 09:19:56.143 25605 25643 I Adreno  : Remote Branch                    : 
05-14 09:19:56.143 25605 25643 I Adreno  : Remote Branch                    : 
05-14 09:19:56.143 25605 25643 I Adreno  : Reconstruct Branch               : 
05-14 09:19:56.145 25605 25643 D vndksupport: Loading /vendor/lib64/hw/gralloc.msm8994.so from current namespace instead of sphal namespace.
05-14 09:19:56.146 25605 25643 I Adreno  : PFP: 0x00000000, ME: 0x00000000
05-14 09:19:56.151 25605 25643 I zygote64: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
05-14 09:19:56.168 25605 25643 I Adreno  : QUALCOMM build                   : 8e59954, I0be83d0d26
05-14 09:19:56.168 25605 25643 I Adreno  : Build Date                       : 09/22/17
05-14 09:19:56.168 25605 25643 I Adreno  : OpenGL ES Shader Compiler Version: EV031.21.02.00
05-14 09:19:56.168 25605 25643 I Adreno  : Local Branch                     : O17A
05-14 09:19:56.168 25605 25643 I Adreno  : Remote Branch                    : 
05-14 09:19:56.168 25605 25643 I Adreno  : Remote Branch                    : 
05-14 09:19:56.168 25605 25643 I Adreno  : Reconstruct Branch               : 
05-14 09:19:56.169 25605 25643 D vndksupport: Loading /vendor/lib64/hw/gralloc.msm8994.so from current namespace instead of sphal namespace.
05-14 09:19:56.171 25605 25643 I Adreno  : PFP: 0x00000000, ME: 0x00000000
05-14 09:19:56.172 25605 25643 I zygote64: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
05-14 09:19:56.187 25605 25643 I Adreno  : QUALCOMM build                   : 8e59954, I0be83d0d26
05-14 09:19:56.187 25605 25643 I Adreno  : Build Date                       : 09/22/17
05-14 09:19:56.187 25605 25643 I Adreno  : OpenGL ES Shader Compiler Version: EV031.21.02.00
05-14 09:19:56.187 25605 25643 I Adreno  : Local Branch                     : O17A
05-14 09:19:56.187 25605 25643 I Adreno  : Remote Branch                    : 
05-14 09:19:56.187 25605 25643 I Adreno  : Remote Branch                    : 
05-14 09:19:56.187 25605 25643 I Adreno  : Reconstruct Branch               : 
05-14 09:19:56.188 25605 25643 D vndksupport: Loading /vendor/lib64/hw/gralloc.msm8994.so
usecf 2021-05-13
  • 打赏
  • 举报
回复
回调错误和正常流程 任何一个都没有进? 把log抓下,贴出来
yhm2046 中级 2021-05-12
  • 打赏
  • 举报
回复
click btn============ //只走到这里,没有进入回调
usecf 2021-05-12
  • 打赏
  • 举报
回复
打印下log看具体运行到那块

80,348

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧