2011-12-08 15 views
2

我正在開發應用程序,因爲我必須獲取過去10天的所有通話和短信記錄。現在,我只能找出所有向我發送短信和所有手機通訊錄的聯繫人。所以,請大家幫我展示一下如何從我的應用程序中查找或獲取最近10天的通話和短信詳細信息?如何從我的應用程序中查找過去10天的通話和短信詳細信息

我的代碼是這樣的:

final Uri SMS_INBOX = Uri.parse("content://sms/inbox"); 

Cursor c = getContentResolver().query(SMS_INBOX, null, "read", null, null); 
int readMessagesCount = c.getCount(); 
Toast.makeText(getApplicationContext(), 
    "Read massage info"+readMessagesCount, 2000).show(); 
c.deactivate(); 
while (c.moveToNext()) { 
    String asd = new String(c.getBlob(c.getColumnIndex("address"))); 
    Toast.makeText(getApplicationContext(), asd, Toast.LENGTH_SHORT).show(); 

回答

2

對於呼叫日誌,你可以使用下面的代碼:它通過與當前日期comapring日期返回日期,你可以過濾不同的最近10天的日誌。

Cursor c = context.getContentResolver().query(
            android.provider.CallLog.Calls.CONTENT_URI, 
            null, null, null, 
            android.provider.CallLog.Calls.DATE + " DESC"); 
           int numberColumn = c.getColumnIndex(
              android.provider.CallLog.Calls.NUMBER); 
           int dateColumn = c.getColumnIndex(
              android.provider.CallLog.Calls.DATE); 

          // type can be: Incoming, Outgoing or Missed 

           int typeColumn = c.getColumnIndex(
             android.provider.CallLog.Calls.TYPE); 
           int DurationColumn = c.getColumnIndex(

            android.provider.CallLog.Calls.DURATION); 

                  if(c.moveToPosition(0)) 
           { 
            String callerPhoneNumber = c.getString(numberColumn); 
            String callerPhoneDate = c.getString(dateColumn); 
            String TYeor = c.getString(typeColumn); 



           String Duration = c.getString(DurationColumn); 
       }   

而且我認爲短信日誌也會返回日期,因此您可以使用與短信日誌相同的邏輯。

+0

我可以在哪裏提到獲得記錄的天數? – Kutbi

+0

嗨bindal..can你請給我一些關於短信日誌的提示.... – Kutbi

+0

@bindal嗨我從android消息應用程序中鍵入一條消息,併發送給你。我寫一個應用程序,並從我的code.how檢索你的號碼這是可能的嗎?請你幫我解決這個問題。請給我發郵件[email protected] – Maidul

相關問題