2017-10-18 13 views
-1

public void refreshSmsInbox(){ ContentResolver contentResolver = getContentResolver(); カーソルsmsInboxCursor = contentResolver.query(Uri.parse( "content:// sms/inbox")、null、null、null、null); int indexBody = smsInboxCursor.getColumnIndex( "body"); int indexAddress = smsInboxCursor.getColumnIndex( "address"); if(indexBody < 0 ||!smsInboxCursor.moveToFirst())return;listviewで送受信されたメッセージを一緒に表示する方法

arrayAdapter.clear(); 
    do { 
     String str = "SMS From: " + smsInboxCursor.getString(indexAddress) + 
       "\n" + smsInboxCursor.getString(indexBody) + "\n"; 
     smsMessagesList.add(str); 
    } while (smsInboxCursor.moveToNext()); 

} 

答えて

0

公共ボイドrefreshSmsInbox(){ ContentResolverのContentResolverの= getContentResolver()。 カーソルsmsInboxCursor = contentResolver.query(Uri.parse( "content:// sms /")、null、null、null、null);

if (smsInboxCursor.getColumnIndex("body") < 0 || !smsInboxCursor.moveToFirst()) return; 
    do { 
     String contactName=smsInboxCursor.getString(smsInboxCursor.getColumnIndex("address")); 
     String mess=smsInboxCursor.getString(smsInboxCursor.getColumnIndex("body")); 

     long timeMillis = smsInboxCursor.getColumnIndex("date"); 
     Date date = new Date(timeMillis); 
     SimpleDateFormat format = new SimpleDateFormat("MM/DD/YY"); 
     String dateText = format.format(date); 

     String hms = String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(timeMillis), 
       TimeUnit.MILLISECONDS.toMinutes(timeMillis) % TimeUnit.HOURS.toMinutes(1), 
       TimeUnit.MILLISECONDS.toSeconds(timeMillis) % TimeUnit.MINUTES.toSeconds(1)); 

     MessageList message=new MessageList(contactName,mess,dateText,hms,R.drawable.receive); 
     smsMessagesList.add(message); 
    } while (smsInboxCursor.moveToNext()); 
} 
関連する問題