Android Smack 4.2如何上传文件?

问题描述 投票:0回答:1

我正在使用Smack 4.2在聊天应用中工作,我可以以1:1的速度发送短信,现在我想发送图像消息。但我可以清楚地找到任何解决方案。

某些问题是旧版本。

希望有人与我分享任何解决方案或文件。

android smack asmack
1个回答
0
投票

您可以使用HttpFileUploadManager上传文件:

  try {
        HttpFileUploadManager httpFileUploadManager = XmppConnection.getInstance().getHttpFileUploadManager();
        XmppConnection.getInstance().discoverHttpService();
        final Slot slot = httpFileUploadManager.requestSlot(file.getName(), file.length(), null,
                JidCreate.domainBareFrom(Globals.getHttpUploadDomain()));

        httpFileUploadManager.uploadFile(file, slot, (uploadedBytes, totalBytes) -> {
            Log.d("totalBytes", ">>>" + totalBytes);
            Log.d("uploadedBytes", ">>>" + uploadedBytes);
            if (totalBytes == uploadedBytes) {
               //handle upload success (Send Message with the url in the body? the url is in slot.getGetUrl().toString();)
            }
        });

    } catch (Exception e) {
        e.printSackTrace();
       //handle failure
    }
© www.soinside.com 2019 - 2024. All rights reserved.