Twilio Chat Media Messaging sends null on Android

不羁岁月 提交于 2021-01-29 08:27:15

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!