/
message.java
209 lines (138 loc) · 7 KB
/
message.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
@Override
public void onRecvNewMessage(V2TIMMessage msg) {
int elemType = msg.getElemType();
if (elemType == V2TIMMessage.V2TIM_ELEM_TYPE_TEXT) {
V2TIMTextElem v2TIMTextElem = msg.getTextElem();
String text = v2TIMTextElem.getText();
} else if (elemType == V2TIMMessage.V2TIM_ELEM_TYPE_CUSTOM) {
V2TIMCustomElem v2TIMCustomElem = msg.getCustomElem();
byte[] customData = v2TIMCustomElem.getData();
} else if (elemType == V2TIMMessage.V2TIM_ELEM_TYPE_IMAGE) {
V2TIMImageElem v2TIMImageElem = msg.getImageElem();
List<V2TIMImageElem.V2TIMImage> imageList = v2TIMImageElem.getImageList();
for (V2TIMImageElem.V2TIMImage v2TIMImage : imageList) {
String uuid = v2TIMImage.getUUID();
int imageType = v2TIMImage.getType();
int size = v2TIMImage.getSize();
int width = v2TIMImage.getWidth();
int height = v2TIMImage.getHeight();
String imagePath = "/sdcard/im/image/" + "myUserID" + uuid;
File imageFile = new File(imagePath);
if (!imageFile.exists()) {
v2TIMImage.downloadImage(imagePath, new V2TIMDownloadCallback() {
@Override
public void onProgress(V2TIMElem.V2ProgressInfo progressInfo) {
}
@Override
public void onError(int code, String desc) {
}
@Override
public void onSuccess() {
}
});
} else {
}
}
} else if (elemType == V2TIMMessage.V2TIM_ELEM_TYPE_SOUND) {
V2TIMSoundElem v2TIMSoundElem = msg.getSoundElem();
String uuid = v2TIMSoundElem.getUUID();
int dataSize = v2TIMSoundElem.getDataSize();
int duration = v2TIMSoundElem.getDuration();
String soundPath = "/sdcard/im/sound/" + "myUserID" + uuid;
File imageFile = new File(soundPath);
if (!imageFile.exists()) {
v2TIMSoundElem.downloadSound(soundPath, new V2TIMDownloadCallback() {
@Override
public void onProgress(V2TIMElem.V2ProgressInfo progressInfo) {
}
@Override
public void onError(int code, String desc) {
}
@Override
public void onSuccess() {
}
});
} else {
}
} else if (elemType == V2TIMMessage.V2TIM_ELEM_TYPE_VIDEO) {
V2TIMVideoElem v2TIMVideoElem = msg.getVideoElem();
String snapshotUUID = v2TIMVideoElem.getSnapshotUUID();
int snapshotSize = v2TIMVideoElem.getSnapshotSize();
int snapshotWidth = v2TIMVideoElem.getSnapshotWidth();
int snapshotHeight = v2TIMVideoElem.getSnapshotHeight();
String videoUUID = v2TIMVideoElem.getVideoUUID();
int videoSize = v2TIMVideoElem.getVideoSize();
int duration = v2TIMVideoElem.getDuration();
String snapshotPath = "/sdcard/im/snapshot/" + "myUserID" + snapshotUUID;
File snapshotFile = new File(snapshotPath);
if (!snapshotFile.exists()) {
v2TIMVideoElem.downloadSnapshot(snapshotPath, new V2TIMDownloadCallback() {
@Override
public void onProgress(V2TIMElem.V2ProgressInfo progressInfo) {
}
@Override
public void onError(int code, String desc) {
}
@Override
public void onSuccess() {
}
});
} else {
}
String videoPath = "/sdcard/im/video/" + "myUserID" + snapshotUUID;
File videoFile = new File(videoPath);
if (!snapshotFile.exists()) {
v2TIMVideoElem.downloadSnapshot(videoPath, new V2TIMDownloadCallback() {
@Override
public void onProgress(V2TIMElem.V2ProgressInfo progressInfo) {
}
@Override
public void onError(int code, String desc) {
}
@Override
public void onSuccess() {
}
});
} else {
}
} else if (elemType == V2TIMMessage.V2TIM_ELEM_TYPE_FILE) {
V2TIMFileElem v2TIMFileElem = msg.getFileElem();
String uuid = v2TIMFileElem.getUUID();
String fileName = v2TIMFileElem.getFileName();
int fileSize = v2TIMFileElem.getFileSize();
String filePath = "/sdcard/im/file/" + "myUserID" + uuid;
File file = new File(filePath);
if (!file.exists()) {
v2TIMFileElem.downloadFile(filePath, new V2TIMDownloadCallback() {
@Override
public void onProgress(V2TIMElem.V2ProgressInfo progressInfo) {
}
@Override
public void onError(int code, String desc) {
}
@Override
public void onSuccess() {
}
});
} else {
}
} else if (elemType == V2TIMMessage.V2TIM_ELEM_TYPE_LOCATION) {
V2TIMLocationElem v2TIMLocationElem = msg.getLocationElem();
String desc = v2TIMLocationElem.getDesc();
double longitude = v2TIMLocationElem.getLongitude();
double latitude = v2TIMLocationElem.getLatitude();
} else if (elemType == V2TIMMessage.V2TIM_ELEM_TYPE_FACE) {
V2TIMFaceElem v2TIMFaceElem = msg.getFaceElem();
int index = v2TIMFaceElem.getIndex();
byte[] data = v2TIMFaceElem.getData();
} else if (elemType == V2TIMMessage.V2TIM_ELEM_TYPE_GROUP_TIPS) {
V2TIMGroupTipsElem v2TIMGroupTipsElem = msg.getGroupTipsElem();
String groupId = v2TIMGroupTipsElem.getGroupID();
int type = v2TIMGroupTipsElem.getType();
V2TIMGroupMemberInfo opMember = v2TIMGroupTipsElem.getOpMember();
List<V2TIMGroupMemberInfo> memberList = v2TIMGroupTipsElem.getMemberList();
List<V2TIMGroupChangeInfo> groupChangeInfoList = v2TIMGroupTipsElem.getGroupChangeInfoList();
List<V2TIMGroupMemberChangeInfo> memberChangeInfoList v2TIMGroupTipsElem.getMemberChangeInfoList();
int memberCount = v2TIMGroupTipsElem.getMemberCount();
}
}