Tôi đang phát triển một chương trình SMS và tôi muốn nhận cuộc trò chuyện.
tôi đã viết đoạn code dưới đây và nó hoạt động tốt, nhưng tôi tự hỏi, nếu nó có thể hiệu quả hơnAndroid nhận cuộc hội thoại qua sms với tên hoặc địa chỉ
này được cho geting chuyện Các luồng
Uri SMS_INBOX = Uri.parse("content://sms/conversations/");
Cursor c = getContentResolver().query(SMS_INBOX, null, null, null, "date desc");
startManagingCursor(c);
String[] count = new String[c.getCount()];
String[] snippet = new String[c.getCount()];
String[] thread_id = new String[c.getCount()];
c.moveToFirst();
for (int i = 0; i < c.getCount(); i++) {
count[i] = c.getString(c.getColumnIndexOrThrow("msg_count"))
.toString();
thread_id[i] = c.getString(c.getColumnIndexOrThrow("thread_id"))
.toString();
snippet[i] = c.getString(c.getColumnIndexOrThrow("snippet"))
.toString();
//Toast.makeText(getApplicationContext(), count[i] + " - " + thread_id[i]+" - "+snippet[i] , Toast.LENGTH_LONG).show();
c.moveToNext();
}
c.close();
để nhận địa chỉ theo chủ đề trò chuyện
for(int ad = 0; ad < thread_id.length ; ad++)
{
Uri uri = Uri.parse("content://sms/inbox");
String where = "thread_id="+thread_id[ad];
Cursor mycursor= getContentResolver().query(uri, null, where ,null,null);
startManagingCursor(mycursor);
String[] number = new String[mycursor.getCount()];
if(mycursor.moveToFirst()){
for(int i=0;i<mycursor.getCount();i++){
number[i]=mycursor.getString(mycursor.getColumnIndexOrThrow("address")).toString();
mycursor.moveToNext();
}
}
mycursor.close();
và cuối cùng kiểm tra các địa chỉ (nếu trong danh sách liên hệ) và thêm vào danh sách
for(int i =0 ; i < numaralar.length ;i++)
{
String a = numaralar[i].substring(0,1);
if(!a.equals("+")){ kisiismi = numaralar[i]; }
ContentResolver localContentResolver = getApplicationContext().getContentResolver();
Cursor contactLookupCursor =
localContentResolver.query(
Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
Uri.encode(numaralar[i])),
new String[] {PhoneLookup.DISPLAY_NAME, PhoneLookup._ID},
null,
null,
null);
try {
while(contactLookupCursor.moveToNext()){
String contactName = contactLookupCursor.getString(contactLookupCursor.getColumnIndexOrThrow(PhoneLookup.DISPLAY_NAME));
kisiismi = contactName;
}
}catch (Exception e) {
kisiismi = numaralar[i].toString();
}
finally {
//Toast.makeText(getApplicationContext(), ad + kisiismi + " " + count[ad], Toast.LENGTH_LONG).show();
myArr.add(kisiismi);
contactLookupCursor.close();
}
}
Có cách nào để làm cho quy trình này dễ dàng hơn không?
Có thể nhận cuộc trò chuyện giữa hai người dùng (tôi và người gửi tin nhắn cho tôi) từ Conversations = "content: // sms/conversation" hay không. nếu vậy thì sao? – Developer
Điều này chưa được đóng lại. Người dùng rõ ràng đang yêu cầu một cách hiệu quả để có được các Threads of messages theo số liên lạc hoặc tên, giống như ứng dụng tin nhắn gốc. Tôi cũng muốn một câu trả lời cho rằng –
Tôi đồng ý, điều này không nên bị đóng. Hy vọng rằng một người nào đó có thể trả lời ít nhất bằng hình thức nhận xét ... – Pkmmte