file - Image is not attached in quickblox for android -


i have made demo sending image private chat using quickblox, struggling attach image chat message, have gone through document , have used below links, no luck attach image

my code 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 message         // ...         int fileid = r.raw.ic_launcher;         inputstream = 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 send message", e);         } catch (smackexception sme) {             log.e(tag, "failed send message", sme);         }          messageedittext.settext("");          if (dialog.gettype() == qbdialogtype.private) {             showmessage(chatmessage);         }      }  }); 

well clear mistake is

your id null here

atach.setid(id+""); 

because != nil in onsuccess block of uploadfiletask

so right way forward attachments logic inside onsuccess block of uploadfiletask

because these quickblox request asynchronous


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -