Android Volley:将图像上传为String时出现CalledFromWrongThreadException

时间:2018-10-23 23:00:34

标签: android android-volley

我正在尝试使用Android中的Volley将图像作为String上载到我的服务器。

仅在较旧的设备上,我会收到CalledFromWrongThreadException。该代码可在较新的设备(Android 7+)上完美运行。

错误消息:

  

E / Volley:[231] NetworkDispatcher.processRequest:未处理的异常android.view.ViewRootImpl $ CalledFromWrongThreadException:仅创建视图层次结构的原始线程可以触摸其视图。

我的POST请求:

{
  "type": "Action.Submit",
  "title": "Click me for messageBack",
  "data": {
    "msteams": {
        "type": "messageBack",
        "displayText": "I clicked this button",
        "text": "text to bots",
        "value": "{\"bfKey\": \"bfVal\", \"conflictKey\": \"from value\"}"
    }
  }
}

1 个答案:

答案 0 :(得分:0)

在请求之外获取图像可以解决问题!

final Bitmap imageBitmap = cropImageView.getCroppedImage();

//REQUEST using imageBitmap below