你的浏览器禁用了JavaScript, 请开启后刷新浏览器获得更好的体验!
输入关键字进行搜索
搜索:
没有找到相关结果
lzan13 - 慢慢来,一步一个脚印?
Bartender
zhangnan
要回复问题请先登录或注册
3 个回复
lzan13 - 慢慢来,一步一个脚印?
还有就是建议使用监听回调来接受消息,不建议使用广播
Bartender
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 时根本收不到
zhangnan