问题
I've been following the Twilio docs to try and send a media message, in this case just a jpg
file. https://www.twilio.com/docs/chat/media-support?code-sample=code-checking-for-media-content-2&code-language=Android%20-%20Java&code-sdk-version=default
My problem is that despite getting the log Successfully sent MEDIA message
my message appears as empty. In fact it's actually null
. Below is the code,
String path = android.os.Environment.getExternalStorageDirectory().toString()+"/DCIM/Camera/20201127_121348.jpg";
try {
messagesObject.sendMessage(
Message.options()
.withMedia(new FileInputStream(path), "image/jpeg")
.withMediaFileName("20201127_121348.jpg")
.withMediaProgressListener(new ProgressListener() {
@Override
public void onStarted() {
System.out.println("Upload started");
}
@Override
public void onProgress(long bytes) {
System.out.println("Uploaded " + bytes + " bytes");
}
@Override
public void onCompleted(String mediaSid) {
System.out.println("Upload completed");
}
}),
new CallbackListener<Message>() {
@Override
public void onSuccess(Message msg) {
System.out.println("Successfully sent MEDIA message");
}
@Override
public void onError(ErrorInfo error) {
System.out.println("Error sending MEDIA message");
}
});
} catch (FileNotFoundException e) {
System.out.println("FAILED HORRIBLY");
System.out.println(e);
e.printStackTrace();
}
From the debug panel I can see:
I/System.out: Upload started
I/System.out: Uploaded 248513 bytes
I/System.out: Uploaded 1456833 bytes
I/System.out: Uploaded 2557913 bytes
I/System.out: Upload completed
D/ConversationPresenter: setMessagesConsumed, onSuccess
I/System.out: Successfully sent MEDIA message
I know the jpg
files exists for the given path as I've checked with the File
object method .exists()
and it returned as true
.
What do I need to do to get the file (in this case just a jpg) to show up in the chat? Thank you.
来源:https://stackoverflow.com/questions/65043955/twilio-chat-media-messaging-sends-null-on-android