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