com.easemob.chat.NormalFileMessageBody Java Examples

The following examples show how to use com.easemob.chat.NormalFileMessageBody. 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: EaseChatRowFile.java    From monolog-android with MIT License 6 votes vote down vote up
@Override
protected void onSetUpView() {
    fileMessageBody = (NormalFileMessageBody) message.getBody();
       String filePath = fileMessageBody.getLocalUrl();
       fileNameView.setText(fileMessageBody.getFileName());
       fileSizeView.setText(TextFormater.getDataSize(fileMessageBody.getFileSize()));
       if (message.direct == EMMessage.Direct.RECEIVE) { // 接收的消息
           File file = new File(filePath);
           if (file != null && file.exists()) {
               fileStateView.setText(R.string.Have_downloaded);
           } else {
               fileStateView.setText(R.string.Did_not_download);
           }
           return;
       }

       // until here, deal with send voice msg
       handleSendMessage();
}
 
Example #2
Source File: ChatActivity.java    From FanXin-based-HuanXin with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 发送文件
 * 
 * @param uri
 */
private void sendFile(Uri uri) {
    String filePath = null;
    if ("content".equalsIgnoreCase(uri.getScheme())) {
        String[] projection = { "_data" };
        Cursor cursor = null;

        try {
            cursor = getContentResolver().query(uri, projection, null,
                    null, null);
            int column_index = cursor.getColumnIndexOrThrow("_data");
            if (cursor.moveToFirst()) {
                filePath = cursor.getString(column_index);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else if ("file".equalsIgnoreCase(uri.getScheme())) {
        filePath = uri.getPath();
    }
    File file = new File(filePath);
    if (file == null || !file.exists()) {
        Toast.makeText(getApplicationContext(), "文件不存在", Toast.LENGTH_SHORT)
                .show();
        return;
    }
    if (file.length() > 10 * 1024 * 1024) {
        Toast.makeText(getApplicationContext(), "文件不能大于10M",
                Toast.LENGTH_SHORT).show();
        return;
    }

    // 创建一个文件消息
    EMMessage message = EMMessage.createSendMessage(EMMessage.Type.FILE);
    // 如果是群聊,设置chattype,默认是单聊
    if (chatType == CHATTYPE_GROUP)
        message.setChatType(ChatType.GroupChat);

    message.setReceipt(toChatUsername);
    // add message body
    NormalFileMessageBody body = new NormalFileMessageBody(new File(
            filePath));
    message.addBody(body);
    message.setAttribute("toUserNick", toUserNick);
    message.setAttribute("toUserAvatar", toUserAvatar);
    message.setAttribute("useravatar", myUserAvatar);
    message.setAttribute("usernick", myUserNick);
    conversation.addMessage(message);
    listView.setAdapter(adapter);
    adapter.refresh();
    listView.setSelection(listView.getCount() - 1);
    setResult(RESULT_OK);
}
 
Example #3
Source File: ChatActivity.java    From school_shop with MIT License 4 votes vote down vote up
/**
 * 发送文件
 * 
 * @param uri
 */
private void sendFile(Uri uri) {
	String filePath = null;
	if ("content".equalsIgnoreCase(uri.getScheme())) {
		String[] projection = { "_data" };
		Cursor cursor = null;

		try {
			cursor = getContentResolver().query(uri, projection, null, null, null);
			int column_index = cursor.getColumnIndexOrThrow("_data");
			if (cursor.moveToFirst()) {
				filePath = cursor.getString(column_index);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	} else if ("file".equalsIgnoreCase(uri.getScheme())) {
		filePath = uri.getPath();
	}
	File file = new File(filePath);
	if (file == null || !file.exists()) {
		String st7 = getResources().getString(R.string.File_does_not_exist);
		Toast.makeText(getApplicationContext(), st7, 0).show();
		return;
	}
	if (file.length() > 10 * 1024 * 1024) {
		String st6 = getResources().getString(R.string.The_file_is_not_greater_than_10_m);
		Toast.makeText(getApplicationContext(), st6, 0).show();
		return;
	}

	// 创建一个文件消息
	EMMessage message = EMMessage.createSendMessage(EMMessage.Type.FILE);
	// 如果是群聊,设置chattype,默认是单聊
	if (chatType == CHATTYPE_GROUP)
		message.setChatType(ChatType.GroupChat);

	message.setReceipt(toChatUsername);
	// add message body
	NormalFileMessageBody body = new NormalFileMessageBody(new File(filePath));
	message.addBody(body);
	conversation.addMessage(message);
	listView.setAdapter(adapter);
	adapter.refreshSelectLast();
	setResult(RESULT_OK);
}