com.easemob.util.EMLog Java Examples

The following examples show how to use com.easemob.util.EMLog. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HXNotifier.java    From school_shop with MIT License 6 votes vote down vote up
/**
 * 处理新收到的消息,然后发送通知
 * 
 * 开发者可以重载此函数
 * this function can be override
 * 
 * @param message
 */
public synchronized void onNewMsg(final EMMessage message) {
    if(EMChatManager.getInstance().isSlientMessage(message)){
        return;
    }
    
    // 判断app是否在后台
    if (!EasyUtils.isAppRunningForeground(appContext)) {
        EMLog.d(TAG, "app is running in backgroud");
        sendNotification(message, false);
    } else {
        sendNotification(message, true);

    }
    
    viberateAndPlayTone(message);
}
 
Example #2
Source File: EaseNotifier.java    From monolog-android with MIT License 6 votes vote down vote up
/**
 * 处理新收到的消息,然后发送通知
 * 
 * 开发者可以重载此函数
 * this function can be override
 * 
 * @param message
 */
public synchronized void onNewMsg(EMMessage message) {
    if(EMChatManager.getInstance().isSlientMessage(message)){
        return;
    }
    EaseSettingsProvider settingsProvider = EaseUI.getInstance().getSettingsProvider();
    if(!settingsProvider.isMsgNotifyAllowed(message)){
        return;
    }
    
    // 判断app是否在后台
    if (!EasyUtils.isAppRunningForeground(appContext)) {
        EMLog.d(TAG, "app is running in backgroud");
        sendNotification(message, false);
    } else {
        sendNotification(message, true);

    }
    
    viberateAndPlayTone(message);
}
 
Example #3
Source File: EaseNotifier.java    From monolog-android with MIT License 6 votes vote down vote up
public synchronized void onNewMesg(List<EMMessage> messages) {
    if(EMChatManager.getInstance().isSlientMessage(messages.get(messages.size()-1))){
        return;
    }
    EaseSettingsProvider settingsProvider = EaseUI.getInstance().getSettingsProvider();
    if(!settingsProvider.isMsgNotifyAllowed(null)){
        return;
    }
    // 判断app是否在后台
    if (!EasyUtils.isAppRunningForeground(appContext)) {
        EMLog.d(TAG, "app is running in backgroud");
        sendNotification(messages, false);
    } else {
        sendNotification(messages, true);
    }
    viberateAndPlayTone(messages.get(messages.size()-1));
}
 
Example #4
Source File: EaseVoiceRecorder.java    From monolog-android with MIT License 6 votes vote down vote up
public int stopRecoding() {
    if(recorder != null){
        isRecording = false;
        recorder.stop();
        recorder.release();
        recorder = null;
        
        if(file == null || !file.exists() || !file.isFile()){
            return EMError.INVALID_FILE;
        }
        if (file.length() == 0) {
            file.delete();
            return EMError.INVALID_FILE;
        }
        int seconds = (int) (new Date().getTime() - startTime) / 1000;
        EMLog.d("voice", "voice recording finished. seconds:" + seconds + " file length:" + file.length());
        return seconds;
    }
    return 0;
}
 
Example #5
Source File: EaseContactAdapter.java    From monolog-android with MIT License 6 votes vote down vote up
@Override
public Object[] getSections() {
    positionOfSection = new SparseIntArray();
    sectionOfPosition = new SparseIntArray();
    int count = getCount();
    list = new ArrayList<String>();
    list.add(getContext().getString(R.string.search_header));
    positionOfSection.put(0, 0);
    sectionOfPosition.put(0, 0);
    for (int i = 1; i < count; i++) {

        String letter = getItem(i).getInitialLetter();
        EMLog.d(TAG, "contactadapter getsection getHeader:" + letter + " name:" + getItem(i).getUsername());
        int section = list.size() - 1;
        if (list.get(section) != null && !list.get(section).equals(letter)) {
            list.add(letter);
            section++;
            positionOfSection.put(section, i);
        }
        sectionOfPosition.put(i, section);
    }
    return list.toArray(new String[list.size()]);
}
 
Example #6
Source File: CallReceiver.java    From school_shop with MIT License 6 votes vote down vote up
@Override
	public void onReceive(Context context, Intent intent) {
		if(!DemoHXSDKHelper.getInstance().isLogined())
		    return;
		//拨打方username
		String from = intent.getStringExtra("from");
		//call type
//		String type = intent.getStringExtra("type");
//		if("video".equals(type)){ //视频通话
//		    context.startActivity(new Intent(context, VideoCallActivity.class).
//                    putExtra("username", from).putExtra("isComingCall", true).
//                    addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
//		}else{ //音频通话
//		    context.startActivity(new Intent(context, VoiceCallActivity.class).
//		            putExtra("username", from).putExtra("isComingCall", true).
//		            addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
//		}
		EMLog.d("CallReceiver", "app received a incoming call");
	}
 
Example #7
Source File: MainActivity.java    From FanXin-based-HuanXin with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onUserRemoved(String groupId, String groupName) {
    // 提示用户被T了,demo省略此步骤
    // 刷新ui
    runOnUiThread(new Runnable() {
        public void run() {
            try {
                updateUnreadLabel();
                if (currentTabIndex == 0)
                    homefragment.refresh();
                // if (CommonUtils.getTopActivity(MainActivity.this)
                // .equals(GroupsActivity.class.getName())) {
                // GroupsActivity.instance.onResume();
                // }
            } catch (Exception e) {
                EMLog.e(TAG, "refresh exception " + e.getMessage());
            }
        }
    });
}
 
Example #8
Source File: RecorderVideoActivity.java    From FanXin-based-HuanXin with GNU General Public License v2.0 6 votes vote down vote up
@SuppressLint("NewApi")
private boolean initCamera() {
	try {
		if (frontCamera == 0) {
			mCamera = Camera.open(CameraInfo.CAMERA_FACING_BACK);
		} else {
			mCamera = Camera.open(CameraInfo.CAMERA_FACING_FRONT);
		}
		Camera.Parameters camParams = mCamera.getParameters();
		mCamera.lock();
		mSurfaceHolder = mVideoView.getHolder();
		mSurfaceHolder.addCallback(this);
		mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
		mCamera.setDisplayOrientation(90);

	} catch (RuntimeException ex) {
		EMLog.e("video", "init Camera fail " + ex.getMessage());
		return false;
	}
	return true;
}
 
Example #9
Source File: RecorderVideoActivity.java    From FanXin-based-HuanXin with GNU General Public License v2.0 6 votes vote down vote up
public void sendVideo(View view) {
	if (TextUtils.isEmpty(localPath)) {
		EMLog.e("Recorder", "recorder fail please try again!");
		return;
	}

	msc = new MediaScannerConnection(this,
			new MediaScannerConnectionClient() {

				@Override
				public void onScanCompleted(String path, Uri uri) {
					System.out.println("scanner completed");
					msc.disconnect();
					setResult(RESULT_OK, getIntent().putExtra("uri", uri));
					finish();
				}

				@Override
				public void onMediaScannerConnected() {
					msc.scanFile(localPath, "video/*");
				}
			});
	msc.connect();

}
 
Example #10
Source File: RecorderVideoActivity.java    From FanXin-based-HuanXin with GNU General Public License v2.0 6 votes vote down vote up
public void stopRecording() {
	if (mediaRecorder != null) {
		mediaRecorder.setOnErrorListener(null);
		mediaRecorder.setOnInfoListener(null);
		try {
			mediaRecorder.stop();
		} catch (IllegalStateException e) {
			EMLog.e("video", "stopRecording error:" + e.getMessage());
		}
	}
	releaseRecorder();

	if (mCamera != null) {
		mCamera.stopPreview();
		releaseCamera();
	}
}
 
Example #11
Source File: EaseChatRowVideo.java    From monolog-android with MIT License 6 votes vote down vote up
@Override
protected void onBubbleClick() {
    VideoMessageBody videoBody = (VideoMessageBody) message.getBody();
       EMLog.d(TAG, "video view is on click");
       Intent intent = new Intent(context, EaseShowVideoActivity.class);
       intent.putExtra("localpath", videoBody.getLocalUrl());
       intent.putExtra("secret", videoBody.getSecret());
       intent.putExtra("remotepath", videoBody.getRemoteUrl());
       if (message != null && message.direct == EMMessage.Direct.RECEIVE && !message.isAcked
               && message.getChatType() != ChatType.GroupChat) {
           message.isAcked = true;
           try {
               EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId());
           } catch (Exception e) {
               e.printStackTrace();
           }
       }
       activity.startActivity(intent);
}
 
Example #12
Source File: EaseImageUtils.java    From monolog-android with MIT License 5 votes vote down vote up
public static String getImagePath(String remoteUrl)
{
	String imageName= remoteUrl.substring(remoteUrl.lastIndexOf("/") + 1, remoteUrl.length());
	String path =PathUtil.getInstance().getImagePath()+"/"+ imageName;
       EMLog.d("msg", "image path:" + path);
       return path;
	
}
 
Example #13
Source File: ImageUtils.java    From school_shop with MIT License 5 votes vote down vote up
public static String getImagePath(String remoteUrl)
{
	String imageName= remoteUrl.substring(remoteUrl.lastIndexOf("/") + 1, remoteUrl.length());
	String path =PathUtil.getInstance().getImagePath()+"/"+ imageName;
       EMLog.d("msg", "image path:" + path);
       return path;
	
}
 
Example #14
Source File: RecorderVideoActivity.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void surfaceCreated(SurfaceHolder holder) {
	if (mCamera == null)
		initCamera();
	try {
		mCamera.setPreviewDisplay(mSurfaceHolder);
		mCamera.startPreview();
		handleSurfaceChanged();
	} catch (IOException e1) {
		EMLog.e("video", "start preview fail " + e1.getMessage());
	}
}
 
Example #15
Source File: RecorderVideoActivity.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onInfo(MediaRecorder mr, int what, int extra) {
	EMLog.v("video", "onInfo");
	if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED) {
		EMLog.v("video", "max duration reached");
		stopRecording();
		btn_switch.setVisibility(View.VISIBLE);
		chronometer.stop();
		btnStart.setVisibility(View.VISIBLE);
		btnStop.setVisibility(View.INVISIBLE);
		chronometer.stop();
		if (localPath == null) {
			return;
		}
		new AlertDialog.Builder(this)
				.setMessage("是否发送?")
				.setPositiveButton(R.string.ok,
						new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface arg0,
									int arg1) {
								arg0.dismiss();
								sendVideo(null);

							}
						}).setNegativeButton(R.string.cancel, null)
				.setCancelable(false).show();
	}

}
 
Example #16
Source File: RecorderVideoActivity.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onError(MediaRecorder mr, int what, int extra) {
	EMLog.e("video", "recording onError:");
	stopRecording();
	Toast.makeText(this,
			"Recording error has occurred. Stopping the recording",
			Toast.LENGTH_SHORT).show();

}
 
Example #17
Source File: DownloadImageTask.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
public static String getThumbnailImagePath(String imagePath) {
    String path = imagePath.substring(0, imagePath.lastIndexOf("/") + 1);
    path += "th" + imagePath.substring(imagePath.lastIndexOf("/")+1, imagePath.length());
    EMLog.d("msg", "original image path:" + imagePath);
    EMLog.d("msg", "thum image path:" + path);
    return path;
}
 
Example #18
Source File: ImageUtils.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
public static String getImagePath(String remoteUrl)
{
	String imageName= remoteUrl.substring(remoteUrl.lastIndexOf("/") + 1, remoteUrl.length());
	String path =PathUtil.getInstance().getImagePath()+"/"+ imageName;
       EMLog.d("msg", "image path:" + path);
       return path;
	
}
 
Example #19
Source File: MainActivity.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 帐号被移除的dialog
 */
private void showAccountRemovedDialog() {
    isAccountRemovedDialogShow = true;
    MYApplication.getInstance().logout(null);
    String st5 = getResources().getString(R.string.Remove_the_notification);
    if (!MainActivity.this.isFinishing()) {
        // clear up global variables
        try {
            if (accountRemovedBuilder == null)
                accountRemovedBuilder = new android.app.AlertDialog.Builder(
                        MainActivity.this);
            accountRemovedBuilder.setTitle(st5);
            accountRemovedBuilder.setMessage(R.string.em_user_remove);
            accountRemovedBuilder.setPositiveButton(R.string.ok,
                    new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog,
                                int which) {
                            dialog.dismiss();
                            accountRemovedBuilder = null;
                            finish();
                            startActivity(new Intent(MainActivity.this,
                                    LoginActivity.class));
                        }
                    });
            accountRemovedBuilder.setCancelable(false);
            accountRemovedBuilder.create().show();
            isCurrentAccountRemoved = true;
        } catch (Exception e) {
            EMLog.e(TAG,
                    "---------color userRemovedBuilder error"
                            + e.getMessage());
        }

    }

}
 
Example #20
Source File: MainActivity.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 显示帐号在别处登录dialog
 */
private void showConflictDialog() {
    isConflictDialogShow = true;
    MYApplication.getInstance().logout(null);
    String st = getResources().getString(R.string.Logoff_notification);
    if (!MainActivity.this.isFinishing()) {
        // clear up global variables
        try {
            if (conflictBuilder == null)
                conflictBuilder = new android.app.AlertDialog.Builder(
                        MainActivity.this);
            conflictBuilder.setTitle(st);
            conflictBuilder.setMessage(R.string.connect_conflict);
            conflictBuilder.setPositiveButton(R.string.ok,
                    new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog,
                                int which) {
                            dialog.dismiss();
                            conflictBuilder = null;
                            finish();
                            startActivity(new Intent(MainActivity.this,
                                    LoginActivity.class));
                        }
                    });
            conflictBuilder.setCancelable(false);
            conflictBuilder.create().show();
            isConflict = true;
        } catch (Exception e) {
            EMLog.e(TAG,
                    "---------color conflictBuilder error" + e.getMessage());
        }

    }

}
 
Example #21
Source File: EaseShowVideoActivity.java    From monolog-android with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	requestWindowFeature(Window.FEATURE_NO_TITLE);
	getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
			WindowManager.LayoutParams.FLAG_FULLSCREEN);
	setContentView(R.layout.ease_showvideo_activity);
	loadingLayout = (RelativeLayout) findViewById(R.id.loading_layout);
	progressBar = (ProgressBar) findViewById(R.id.progressBar);
	localFilePath = getIntent().getStringExtra("localpath");
	String remotepath = getIntent().getStringExtra("remotepath");
	String secret = getIntent().getStringExtra("secret");
	EMLog.d(TAG, "show video view file:" + localFilePath
			+ " remotepath:" + remotepath + " secret:" + secret);
	if (localFilePath != null && new File(localFilePath).exists()) {
		Intent intent = new Intent(Intent.ACTION_VIEW);
		intent.setDataAndType(Uri.fromFile(new File(localFilePath)),
				"video/mp4");
		startActivity(intent);
		finish();
	} else if (!TextUtils.isEmpty(remotepath) && !remotepath.equals("null")) {
		EMLog.d(TAG, "download remote video file");
		Map<String, String> maps = new HashMap<String, String>();
		if (!TextUtils.isEmpty(secret)) {
			maps.put("share-secret", secret);
		}
		downloadVideo(remotepath, maps);
	} else {

	}
}
 
Example #22
Source File: DemoHXSDKHelper.java    From school_shop with MIT License 5 votes vote down vote up
@Override
public HXNotifier createNotifier(){
    return new HXNotifier(){
        public synchronized void onNewMsg(final EMMessage message) {
            if(EMChatManager.getInstance().isSlientMessage(message)){
                return;
            }
            
            String chatUsename = null;
            List<String> notNotifyIds = null;
            // 获取设置的不提示新消息的用户或者群组ids
            if (message.getChatType() == ChatType.Chat) {
                chatUsename = message.getFrom();
                notNotifyIds = ((DemoHXSDKModel) hxModel).getDisabledGroups();
            } else {
                chatUsename = message.getTo();
                notNotifyIds = ((DemoHXSDKModel) hxModel).getDisabledIds();
            }

            if (notNotifyIds == null || !notNotifyIds.contains(chatUsename)) {
                // 判断app是否在后台
                if (!EasyUtils.isAppRunningForeground(appContext)) {
                    EMLog.d(TAG, "app is running in backgroud");
                    sendNotification(message, false);
                } else {
                    sendNotification(message, true);

                }
                
                viberateAndPlayTone(message);
            }
        }
    };
}
 
Example #23
Source File: EaseChatFragment.java    From monolog-android with MIT License 5 votes vote down vote up
protected void onChatRoomViewCreation() {
    final ProgressDialog pd = ProgressDialog.show(getActivity(), "", "Joining......");
    EMChatManager.getInstance().joinChatRoom(toChatUsername, new EMValueCallBack<EMChatRoom>() {

        @Override
        public void onSuccess(final EMChatRoom value) {
            getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    if(getActivity().isFinishing() || !toChatUsername.equals(value.getUsername()))
                        return;
                    pd.dismiss();
                    EMChatRoom room = EMChatManager.getInstance().getChatRoom(toChatUsername);
                    if (room != null) {
                        titleBar.setTitle(room.getName());
                    } else {
                        titleBar.setTitle(toChatUsername);
                    }
                    EMLog.d(TAG, "join room success : " + room.getName());
                    addChatRoomChangeListenr();
                    onConversationInit();
                    onMessageListInit();
                }
            });
        }

        @Override
        public void onError(final int error, String errorMsg) {
            // TODO Auto-generated method stub
            EMLog.d(TAG, "join room failure : " + error);
            getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    pd.dismiss();
                }
            });
            getActivity().finish();
        }
    });
}
 
Example #24
Source File: EaseContactAdapter.java    From monolog-android with MIT License 5 votes vote down vote up
@Override
protected synchronized void publishResults(CharSequence constraint,
        FilterResults results) {
    userList.clear();
    userList.addAll((List<EaseUser>)results.values);
    EMLog.d(TAG, "publish contacts filter results size: " + results.count);
    if (results.count > 0) {
        notiyfyByFilter = true;
        notifyDataSetChanged();
        notiyfyByFilter = false;
    } else {
        notifyDataSetInvalidated();
    }
}
 
Example #25
Source File: DownloadImageTask.java    From school_shop with MIT License 5 votes vote down vote up
public static String getThumbnailImagePath(String imagePath) {
    String path = imagePath.substring(0, imagePath.lastIndexOf("/") + 1);
    path += "th" + imagePath.substring(imagePath.lastIndexOf("/")+1, imagePath.length());
    EMLog.d("msg", "original image path:" + imagePath);
    EMLog.d("msg", "thum image path:" + path);
    return path;
}
 
Example #26
Source File: MessageAdapter.java    From school_shop with MIT License 4 votes vote down vote up
/**
 * load image into image view
 * 
 * @param thumbernailPath
 * @param iv
 * @param position
 * @return the image exists or not
 */
private boolean showImageView(final String thumbernailPath, final ImageView iv, final String localFullSizePath, String remoteDir,
		final EMMessage message) {
	// String imagename =
	// localFullSizePath.substring(localFullSizePath.lastIndexOf("/") + 1,
	// localFullSizePath.length());
	// final String remote = remoteDir != null ? remoteDir+imagename :
	// imagename;
	final String remote = remoteDir;
	EMLog.d("###", "local = " + localFullSizePath + " remote: " + remote);
	// first check if the thumbnail image already loaded into cache
	Bitmap bitmap = ImageCache.getInstance().get(thumbernailPath);
	if (bitmap != null) {
		// thumbnail image is already loaded, reuse the drawable
		iv.setImageBitmap(bitmap);
		iv.setClickable(true); 
		iv.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				System.err.println("image view on click");
				Intent intent = new Intent(activity, ShowBigImage.class);
				File file = new File(localFullSizePath);
				if (file.exists()) {
					Uri uri = Uri.fromFile(file);
					intent.putExtra("uri", uri);
					System.err.println("here need to check why download everytime");
				} else {
					// The local full size pic does not exist yet.
					// ShowBigImage needs to download it from the server
					// first
					// intent.putExtra("", message.get);
					ImageMessageBody body = (ImageMessageBody) message.getBody();
					intent.putExtra("secret", body.getSecret());
					intent.putExtra("remotepath", remote);
				}
				if (message != null && message.direct == EMMessage.Direct.RECEIVE && !message.isAcked
						&& message.getChatType() != ChatType.GroupChat) {
					try {
						EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId());
						message.isAcked = true;
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
				activity.startActivity(intent);
			}
		});
		return true;
	} else {

		new LoadImageTask().execute(thumbernailPath, localFullSizePath, remote, message.getChatType(), iv, activity, message);
		return true;
	}

}
 
Example #27
Source File: ImageUtils.java    From school_shop with MIT License 4 votes vote down vote up
public static String getThumbnailImagePath(String thumbRemoteUrl) {
String thumbImageName= thumbRemoteUrl.substring(thumbRemoteUrl.lastIndexOf("/") + 1, thumbRemoteUrl.length());
String path =PathUtil.getInstance().getImagePath()+"/"+ "th"+thumbImageName;
      EMLog.d("msg", "thum image path:" + path);
      return path;
  }
 
Example #28
Source File: DemoHXSDKHelper.java    From school_shop with MIT License 4 votes vote down vote up
/**
 * 全局事件监听
 * 因为可能会有UI页面先处理到这个消息,所以一般如果UI页面已经处理,这里就不需要再次处理
 * activityList.size() <= 0 意味着所有页面都已经在后台运行,或者已经离开Activity Stack
 */
protected void initEventListener() {
    eventListener = new EMEventListener() {
        
        @Override
        public void onEvent(EMNotifierEvent event) {
            
            switch (event.getEvent()) {
            case EventNewMessage:
            {
                EMMessage message = (EMMessage)event.getData();
                EMLog.d(TAG, "receive the event : " + event.getEvent() + ",id : " + message.getMsgId());
                
                //应用在后台,不需要刷新UI,通知栏提示新消息
                if(activityList.size() <= 0){
                    HXSDKHelper.getInstance().getNotifier().onNewMsg(message);
                }

                break;
            }
            // below is just giving a example to show a cmd toast, the app should not follow this
            // so be careful of this
            case EventNewCMDMessage:
            {
                EMMessage message = (EMMessage)event.getData();
                EMLog.d(TAG, "receive the event : " + event.getEvent() + ",id : " + message.getMsgId());
                
                EMLog.d(TAG, "收到透传消息");
                //获取消息body
                CmdMessageBody cmdMsgBody = (CmdMessageBody) message.getBody();
                final String action = cmdMsgBody.action;//获取自定义action
                
                //获取扩展属性 此处省略
                //message.getStringAttribute("");
                EMLog.d(TAG, String.format("透传消息:action:%s,message:%s", action,message.toString()));
                final String str = appContext.getString(R.string.receive_the_passthrough);
                
                final String CMD_TOAST_BROADCAST = "easemob.demo.cmd.toast";
                IntentFilter cmdFilter = new IntentFilter(CMD_TOAST_BROADCAST);
                
                //注册通话广播接收者
                appContext.registerReceiver(new BroadcastReceiver(){

                    @Override
                    public void onReceive(Context context, Intent intent) {
                        // TODO Auto-generated method stub
                        Toast.makeText(appContext, intent.getStringExtra("cmd_value"), Toast.LENGTH_SHORT).show();
                    }
                    
                }, cmdFilter); 
                

                Intent broadcastIntent = new Intent(CMD_TOAST_BROADCAST);
                broadcastIntent.putExtra("cmd_value", str+action);
                appContext.sendBroadcast(broadcastIntent, null);
                
                break;
            }
            // add other events in case you are interested in
            default:
                break;
            }
            
        }
    };
    
    EMChatManager.getInstance().registerEventListener(eventListener);
}
 
Example #29
Source File: LoginActivity.java    From school_shop with MIT License 4 votes vote down vote up
private void processContactsAndGroups() throws EaseMobException {
    // demo中简单的处理成每次登陆都去获取好友username,开发者自己根据情况而定
    List<String> usernames = EMContactManager.getInstance().getContactUserNames();
    EMLog.d("roster", "contacts size: " + usernames.size());
    Map<String, User> userlist = new HashMap<String, User>();
    for (String username : usernames) {
        User user = new User();
        user.setUsername(username);
        setUserHearder(username, user);
        userlist.put(username, user);
    }
    // 添加user"申请与通知"
    User newFriends = new User();
    newFriends.setUsername(Constants.NEW_FRIENDS_USERNAME);
    String strChat = getResources().getString(R.string.Application_and_notify);
    newFriends.setNick(strChat);
    
    userlist.put(Constants.NEW_FRIENDS_USERNAME, newFriends);
    // 添加"群聊"
    User groupUser = new User();
    String strGroup = getResources().getString(R.string.group_chat);
    groupUser.setUsername(Constants.GROUP_USERNAME);
    groupUser.setNick(strGroup);
    groupUser.setHeader("");
    userlist.put(Constants.GROUP_USERNAME, groupUser);

    // 存入内存
    MyApplication.getInstance().setContactList(userlist);
    System.out.println("----------------"+userlist.values().toString());
    // 存入db
    UserDao dao = new UserDao(LoginActivity.this);
    List<User> users = new ArrayList<User>(userlist.values());
    dao.saveContactList(users);
    
    //获取黑名单列表
    List<String> blackList = EMContactManager.getInstance().getBlackListUsernamesFromServer();
    //保存黑名单
    EMContactManager.getInstance().saveBlackList(blackList);

    // 获取群聊列表(群聊里只有groupid和groupname等简单信息,不包含members),sdk会把群组存入到内存和db中
    EMGroupManager.getInstance().getGroupsFromServer();
}
 
Example #30
Source File: MessageAdapter.java    From FanXin-based-HuanXin with GNU General Public License v2.0 4 votes vote down vote up
/**
 * load image into image view
 * 
 * @param thumbernailPath
 * @param iv
 * @param position
 * @return the image exists or not
 */
private boolean showImageView(final String thumbernailPath,
        final ImageView iv, final String localFullSizePath,
        String remoteDir, final EMMessage message) {
    // String imagename =
    // localFullSizePath.substring(localFullSizePath.lastIndexOf("/") + 1,
    // localFullSizePath.length());
    // final String remote = remoteDir != null ? remoteDir+imagename :
    // imagename;
    final String remote = remoteDir;
    EMLog.d("###", "local = " + localFullSizePath + " remote: " + remote);
    // first check if the thumbnail image already loaded into cache
    Bitmap bitmap = ImageCache.getInstance().get(thumbernailPath);
    if (bitmap != null) {
        // thumbnail image is already loaded, reuse the drawable
        iv.setImageBitmap(bitmap);
        iv.setClickable(true);
        iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                System.err.println("image view on click");
                Intent intent = new Intent(activity, ShowBigImage.class);
                File file = new File(localFullSizePath);
                if (file.exists()) {
                    Uri uri = Uri.fromFile(file);
                    intent.putExtra("uri", uri);
                    System.err
                            .println("here need to check why download everytime");
                } else {
                    // The local full size pic does not exist yet.
                    // ShowBigImage needs to download it from the server
                    // first
                    // intent.putExtra("", message.get);
                    ImageMessageBody body = (ImageMessageBody) message
                            .getBody();
                    intent.putExtra("secret", body.getSecret());
                    intent.putExtra("remotepath", remote);
                }
                if (message != null
                        && message.direct == EMMessage.Direct.RECEIVE
                        && !message.isAcked
                        && message.getChatType() != ChatType.GroupChat) {
                    try {
                        EMChatManager.getInstance().ackMessageRead(
                                message.getFrom(), message.getMsgId());
                        message.isAcked = true;
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                activity.startActivity(intent);
            }
        });
        return true;
    } else {

        new LoadImageTask().execute(thumbernailPath, localFullSizePath,
                remote, message.getChatType(), iv, activity, message);
        return true;
    }

}