图像不在quickblox为Android附 [英] Image is not attached in quickblox for android

查看:180
本文介绍了图像不在quickblox为Android附的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经做了演示使用QuickBlox发送图像私人聊天,我奋力与聊天消息附加一个形象,我已经通过其文件不见了,已经使用了下面的链接,没有运气
附加图片

我的code是如下:

  chatMessage =新QBChatMessage();sendButton =(按钮)findViewById(R.id.chatSendButton);
sendButton.setOnClickListener(新View.OnClickListener(){
    @覆盖
    公共无效的onClick(视图v){
        。最后弦乐MessageText中= messageEditText.getText()的toString();
        如果(TextUtils.isEmpty(MessageText中)){
            返回;
        }        //发送聊天信息
        //        // 发送一个消息
        // ...
        INT FILEID = R.raw.ic_launcher;
        InputStream为= ChatActivity.this.getResources()
                        .openRawResource(FILEID);
        文件fil​​e = FileHelper.getFileInputStream(是,
                        sample_file.png,MYFILE);        布尔fileIsPublic =真;        QBContent.uploadFileTask(文件,fileIsPublic,MessageText中,
                        新QBEntityCallbackImpl< QBFile>(){
                    @覆盖
                    公共无效的onSuccess(QBFile qbFile,捆绑PARAMS){                        串publicUrl = qbFile.getPublicUrl();
                        System.out的
                                        .println(==========图像上传成功++++++++
                                                + publicUrl);                         ID = qbFile.getId();                        System.out的
                                        .println(===================图片ID +++++++++++
                                                + ID +);                    }                    @覆盖
                    公共无效onerror的(名单<串GT;错误){
                        System.out的
                                        .println(==========图像上传错误++++++++
                                                + errors.toString());                    }
                },新QBProgressCallback(){
                    @覆盖
                    公共无效onProgressUpdate(INT进展){                    }
                });
        QBAttachment atach =新QBAttachment(图像);
                atach.setId(ID +);
        ArrayList的< QBAttachment> aryatch =新的ArrayList< QBAttachment>();
        aryatch.add(atach);
        chatMessage.setAttachments(aryatch);
        chatMessage.setBody(MessageText中);
        chatMessage.setProperty(PROPERTY_SAVE_TO_HISTORY,1);
        chatMessage.setDateSent(新的日期()的getTime()/ 1000);        尝试{
            chat.sendMessage(chatMessage);
        }赶上(XMPPException E){
            Log.e(TAG,无法发送邮件,E);
        }赶上(SmackException SME){
            Log.e(TAG,无法发送邮件,SME)。
        }        messageEditText.setText();        如果(dialog.getType()== QBDialogType.PRIVATE){
            showMessage(chatMessage);
        }    }});


解决方案

那么清楚其中的错误是

您的标识为空在这里

  atach.setId(ID +);

,因为它会!=零只在的onSuccess uploadFileTask

所以,正确的方法是内部转发所有附件的逻辑的onSuccess uploadFileTask

由于这些QuickBlox请求都是异步

I have made a demo for sending image to private chat using QuickBlox, I am struggling to attach an image with the chat message, I have gone through its document and have used the below Links, with no luck Attach an image

My code is as below:

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);
        }

    }

});

解决方案

Well it clear where the mistake is

your id is null here

atach.setId(id+"");

because it will != nil only in onSuccess block of uploadFileTask

So the right way is to forward all attachments logic inside onSuccess block of uploadFileTask

Because these QuickBlox request are asynchronous

这篇关于图像不在quickblox为Android附的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆