注册

android 无法实现接收图片

发送图片的代码
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(){
@Override
public void onSuccess() {
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(Talk.this, "发送图片成功", Toast.LENGTH_SHORT).show();
}
});
}

@Override
public void onError(int i, String s) {

}

@Override
public void onProgress(int i, String s) {
}
});
}
});
广播接收代码:
private class NewMessageBroadcastReceiver extends BroadcastReceiver {
@Override
public 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 时根本收不到
已邀请:

lizg - ……

先看下图片发送是否成功了

要回复问题请先登录注册