1
我正在研究android中的quickblox消息附件功能。quickbloxsdk:通过的对象不是文件,不正确的内容类型?
我想要做的是:OnViewClicked
一个CreateChooser(type:images/*)
将会开放。 选择图像后,它会来onActivityResult
方法,它存储Uri
。 发布sendAttachment
函数正在被调用。
这里是我的代码化部:
private Uri uri;
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case FILE_SELECT_CODE:
if (resultCode == RESULT_OK) {
// Get the Uri of the selected file
uri = data.getData();
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
public void sendAttachment() {
File filePhoto = new File(uri.getPath());
Boolean fileIsPublic = false;
QBContent.uploadFileTask(filePhoto, fileIsPublic, null, new QBProgressCallback() {
@Override
public void onProgressUpdate(int i) {
// i - progress in percentages
Log.e(TAG, "onProgressUpdate: " + i);
}
}).performAsync(new QBEntityCallback<QBFile>() {
@Override
public void onSuccess(QBFile qbFile, Bundle bundle) {
Integer id = qbFile.getId();
// create a message
QBChatMessage chatMessage = new QBChatMessage();
chatMessage.setProperty("save_to_history", "1"); // Save a message to history
// attach a photo
QBAttachment attachment = new QBAttachment("photo");
attachment.setId(qbFile.getId().toString());
chatMessage.setBody("");
chatMessage.addAttachment(attachment);
// send a message
try {
mQBChatDialog.sendMessage(chatMessage);
mtvEmpty.setVisibility(View.INVISIBLE);
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
}
}
@Override
public void onError(QBResponseException errors) {
Log.e("DATA", TextUtils.join(",", errors.getErrors()));
}
});
}
logcat的错误:
E/ERROR: File upload onError,File does not exist,Passed object is not file,Incorrect content type
可以请您分享这些问题的示例代码。我必须从camara/gallery上传图片 – Pallavi
@Pallavi你究竟想要什么? 我的意思是uploadFileTask only或文件选择来自gallary + uploadFileTask? – buzzingsilently
我有gallary部分,但我想同步 – Pallavi