GetSMS

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
public ist<SMSModelsDto> getSMS() {
Uri uriSMSURI = Uri.parse("content://sms/");
ContentResolver cr = getContentResolver();
c = cr.query(uriSMSURI, null, null, null, null);
startManagingCursor(c);
if (c.moveToFirst()) {
for (int i = 0; i < c.getCount(); i++) {
String header = c.getString(c.getColumnIndexOrThrow("address"));
if (stringSMSModelsDtoHashMap.containsKey(header)) {
smsModelsDto = stringSMSModelsDtoHashMap.get(header);
smsModelsDto.setRepeatCount(smsModelsDto.getRepeatCount() + 1);
stringSMSModelsDtoHashMap.put(header, smsModelsDto);
} else {
smsModelsDto = new SMSModelsDto();
smsModelsDto.setId(c.getString(c.getColumnIndexOrThrow("_id")));
String threadId = null;
threadId = c.getString(c.getColumnIndexOrThrow("thread_id"));;
if(threadId != null){
smsModelsDto.setThreadId(threadId);
}
smsModelsDto.setHeader(header);
smsModelsDto.setName(header);
smsModelsDto.setBody(c.getString(c.getColumnIndexOrThrow("body")));
smsModelsDto.setRead(Byte.parseByte(c.getString(c.getColumnIndex("read"))));
smsModelsDto.setDate(Long.parseLong(c.getString(c.getColumnIndexOrThrow("date"))));
if (c.getString(c.getColumnIndexOrThrow("type")).contains("1")) {
smsModelsDto.setType((byte) 1);
} else {
smsModelsDto.setType((byte) 0);
}
stringSMSModelsDtoHashMap.put(header, smsModelsDto);
}
if (sms.contains(smsModelsDto)) {
sms.set(sms.indexOf(smsModelsDto), smsModelsDto);
} else {
sms.add(smsModelsDto);
}
runOnUiThread(new Runnable() {
@Override
public void run() {
adapter.notifyDataSetChanged();
}
});
c.moveToNext();
}
if (PermissionCheck.readAndWriteContacts(HomeActivity.this)) {
loadContactsData();
}
}
return sms;
}
public class SMSModelsDto{
private String id;
private String threadId;
private String header;
private String body;
private long date;
private String name;
private String image;
private byte type;
private byte read;
private int repeatCount = 1;
private boolean supportReply = false;
public String getThreadId() {
return threadId;
}
public void setThreadId(String threadId) {
this.threadId = threadId;
}
public boolean isSupportReply() {
return supportReply;
}
public void setSupportReply(boolean supportReply) {
this.supportReply = supportReply;
}
public String getHeader(){
return header;
}
public void setHeader(String header){
this.header = header;
}
public String getBody(){
return body;
}
public void setBody(String body){
this.body = body;
}
public long getDate() {
return date;
}
public void setDate(long date) {
this.date = date;
}
public byte getType(){
return type;
}
public void setType(byte type){
this.type = type;
}
public String getId(){
return id;
}
public void setId(String id){
this.id = id;
}
public byte getRead(){
return read;
}
public void setRead(byte read){
this.read = read;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public int getRepeatCount(){
return repeatCount;
}
public void setRepeatCount(int repeatCount){
this.repeatCount = repeatCount;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString(){
return "SMSModelsDto{" +
"id='" + id + '\'' +
", header='" + header + '\'' +
", body='" + body + '\'' +
", date='" + date + '\'' +
", image=" + image +
", type=" + type +
", read=" + read +
'}';
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX