图像不附加在quickblox为android



我做了一个使用QuickBlox发送图像到私人聊天的演示,我正在努力将图像与聊天消息联系起来,我已经浏览了它的文档并使用了下面的链接,没有运气附加图片

我的代码如下:
chatMessage = new QBChatMessage();
sendButton = (Button) findViewById(R.id.chatSendButton);
sendButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        final String messageText = messageEditText.getText().toString();
        if (TextUtils.isEmpty(messageText)) {
            return;
        }
        // Send chat message
        //
        // send a message
        // ...
        int fileId = R.raw.ic_launcher;
        InputStream is = ChatActivity.this.getResources()
                        .openRawResource(fileId);
        File file = FileHelper.getFileInputStream(is,
                        "sample_file.png", "myFile");
        Boolean fileIsPublic = true;
        QBContent.uploadFileTask(file, fileIsPublic, messageText,
                        new QBEntityCallbackImpl<QBFile>() {
                    @Override
                    public void onSuccess(QBFile qbFile, Bundle params) {
                        String publicUrl = qbFile.getPublicUrl();
                        System.out
                                        .println("==========image uploaded success++++++++"
                                                + publicUrl);
                         id = qbFile.getId();
                        System.out
                                        .println("===================image id+++++++++++"
                                                + id + "");
                    }
                    @Override
                    public void onError(List<String> errors) {
                        System.out
                                        .println("==========image uploaded Errors++++++++"
                                                + errors.toString());
                    }
                }, new QBProgressCallback() {
                    @Override
                    public void onProgressUpdate(int progress) {
                    }
                });
        QBAttachment atach = new QBAttachment("image");
                atach.setId(id+"");

        ArrayList<QBAttachment> aryatch = new ArrayList<QBAttachment>();
        aryatch.add(atach);
        chatMessage.setAttachments(aryatch);
        chatMessage.setBody(messageText);
        chatMessage.setProperty(PROPERTY_SAVE_TO_HISTORY, "1");
        chatMessage.setDateSent(new Date().getTime() / 1000);
        try {
            chat.sendMessage(chatMessage);
        } catch (XMPPException e) {
            Log.e(TAG, "failed to send a message", e);
        } catch (SmackException sme) {
            Log.e(TAG, "failed to send a message", sme);
        }
        messageEditText.setText("");
        if (dialog.getType() == QBDialogType.PRIVATE) {
            showMessage(chatMessage);
        }
    }
});

很明显错误在哪里

你的id这里是null

atach.setId(id+"");

因为它只会在uploadFileTask的onSuccess块中= nil 所以正确的方法是在uploadFileTaskonSuccess块中转发所有的附件逻辑

因为这些QuickBlox请求是异步的

相关内容

  • 没有找到相关文章

最新更新