i'm developing an android application using quickblox, i use custom object for store one file for every user. I do a multiple download request, where i download multiple images, all files are downloaded correctly, but i need to know userid for every downloaded file... i try get this information from callback, but i can't get this information on event onComplete for every downloaded file. There is a way to know user owner?
here is my code:
QBCustomObjectRequestBuilder requestBuilder = new QBCustomObjectRequestBuilder();
requestBuilder.setPagesLimit(100);
requestBuilder.or("idutente", lista);
QBCustomObjects.getObjects("foto", requestBuilder, new QBCallbackImpl() {
@Override
public void onComplete(Result result) {
if (result.isSuccess()) {
QBCustomObjectLimitedResult coresult = (QBCustomObjectLimitedResult) result;
final ArrayList<QBCustomObject> co = coresult.getCustomObjects();
for (int i = 0 ; i < co.size() ; i++) {
QBCustomObject qbCustomObject = new QBCustomObject("foto", String.valueOf(co.get(i).getCustomObjectId()));
QBCustomObjectsFiles.downloadFile(qbCustomObject, "immagine", new QBCallbackImpl() {
@Override
public void onComplete(Result result) {
QBFileDownloadResult downloadResult = (QBFileDownloadResult) result;
if (result.isSuccess()) {
HERE I NEED TO KNOW THE USER ID OF THE FILE DOWNLOADED
// extract file
byte[] content = downloadResult.getContent(); // that's downloaded file content
InputStream is = downloadResult.getContentStream(); // that's downloaded file content
File sdCard = Environment.getExternalStorageDirectory();
File dir = new File (sdCard.getAbsolutePath() + "/quenchat/");
dir.mkdirs();
File cacheFile = new File(dir, "profilo_"+downloadResult.toString()+".png");
BufferedOutputStream bos;
try {
bos = new BufferedOutputStream(new FileOutputStream(cacheFile));
bos.write(content);
bos.flush();
bos.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
});
}
}
}
});
Thank you
You can use context for this purpose
Read more about context here http://quickblox.com/developers/Android#Performing_actions_with_context
The right answer will be:
QBCustomObject qbCustomObject = new QBCustomObject("foto", String.valueOf(co.get(i).getCustomObjectId()));
String userID = String.valueOf(qbCustomObject.getUserId());
QBCustomObjectsFiles.downloadFile(qbCustomObject, "immagine", new QBCallbackImpl() {
@Override
public void onComplete(Result result, Object context) {
QBFileDownloadResult downloadResult = (QBFileDownloadResult) result;
if (result.isSuccess()) {
int userID = Integer.parseInt((String)context);
}
}
}, userID);