问题描述
Error:(130, 68) 错误: 需要包含DemoHelper.MyContactListener的封闭实例
解决方案
参照demo中的DemoHelper类中的这个类实现下了 public class MyContactListener implements EMContactListener { @Override public void onContactAdded(String username) { // 保存增加的联系人 Map<String, EaseUser> localUsers = getContactList(); Map<String, EaseUser> toAddUsers = new HashMap<String, EaseUser>(); EaseUser user = new EaseUser(username); // 添加好友时可能会回调added方法两次 if (!localUsers.containsKey(username)) { userDao.saveContact(user); } toAddUsers.put(username, user); localUsers.putAll(toAddUsers); //发送好友变动广播 broadcastManager.sendBroadcast(new Intent(Constant.ACTION_CONTACT_CHANAGED)); } @Override public void onContactDeleted(String username) { // 被删除 Map<String, EaseUser> localUsers = DemoHelper.getInstance().getContactList(); localUsers.remove(username); userDao.deleteContact(username); inviteMessgeDao.deleteMessage(username); //发送好友变动广播 broadcastManager.sendBroadcast(new Intent(Constant.ACTION_CONTACT_CHANAGED)); } @Override public void onContactInvited(String username, String reason) { // 接到邀请的消息,如果不处理(同意或拒绝),掉线后,服务器会自动再发过来,所以客户端不需要重复提醒 List<InviteMessage> msgs = inviteMessgeDao.getMessagesList(); for (InviteMessage inviteMessage : msgs) { if (inviteMessage.getGroupId() == null && inviteMessage.getFrom().equals(username)) { inviteMessgeDao.deleteMessage(username); } } // 自己封装的javabean InviteMessage msg = new InviteMessage(); msg.setFrom(username); msg.setTime(System.currentTimeMillis()); msg.setReason(reason); Log.d(TAG, username + "请求加你为好友,reason: " + reason); // 设置相应status msg.setStatus(InviteMesageStatus.BEINVITEED); notifyNewIviteMessage(msg); broadcastManager.sendBroadcast(new Intent(Constant.ACTION_CONTACT_CHANAGED)); } @Override public void onContactAgreed(String username) { List<InviteMessage> msgs = inviteMessgeDao.getMessagesList(); for (InviteMessage inviteMessage : msgs) { if (inviteMessage.getFrom().equals(username)) { return; } } // 自己封装的javabean InviteMessage msg = new InviteMessage(); msg.setFrom(username); msg.setTime(System.currentTimeMillis()); Log.d(TAG, username + "同意了你的好友请求"); msg.setStatus(InviteMesageStatus.BEAGREED); notifyNewIviteMessage(msg); broadcastManager.sendBroadcast(new Intent(Constant.ACTION_CONTACT_CHANAGED)); } @Override public void onContactRefused(String username) { // 参考同意,被邀请实现此功能,demo未实现 Log.d(username, username + "拒绝了你的好友请求"); } }
解决方案二:
基本上知道怎么搞了,环信的开发人员怎么能把一个不是静态类放入内部类里面呢,这样直接实例化当然报错了