问题描述
发送图片的代码conversation = EMChatManager.getInstance().getConversation(toChatUsername);message = EMMessage.createSendMessage(EMMessage.Type.IMAGE);ImageMessageBody body = new ImageMessageBody(new File("/storage/emulated/0/DCIM/Camera/IMG_20151018_231159.jpg"));message.addBody(body);message.setReceipt(toChatUsername);conversation.addMessage(message);EMChatManager.getInstance().sendMessage(message, new EMCallBack(){@Overridepublic void onSuccess() {runOnUiThread(new Runnable() {public void run() {Toast.makeText(Talk.this, "发送图片成功", Toast.LENGTH_SHORT).show();}});}@Overridepublic void onError(int i, String s) {}@Overridepublic void onProgress(int i, String s) {}});}});广播接收代码:private class NewMessageBroadcastReceiver extends BroadcastReceiver {@Overridepublic void onReceive(Context context, Intent intent) {// 注销广播abortBroadcast();// 消息id(每条消息都会生成唯一的一个id,目前是SDK生成)String msgId = intent.getStringExtra("msgid");//发送方String username = intent.getStringExtra("from");EMMessage message = EMChatManager.getInstance().getMessage(msgId);EMConversation conversation = EMChatManager.getInstance().getConversation(username);Intent intent1=new Intent();intent1.setAction("android.com.example.broadcastreceiver.action.MYACTION");toChatUsername=username;Toast.makeText(getApplicationContext(),"类型:"+message.getType()+"",Toast.LENGTH_SHORT).show();if(message.getType()==EMMessage.Type.IMAGE){intent1.putExtra("msg", username);ImageMessageBody body = (ImageMessageBody)message.getBody();intent1.putExtra("msg_body", body.getFileName());}但是接收图片时 NewMessageBroadcastReceiver 时根本收不到
解决方案
先看下图片发送是否成功了