未読情報の取得


package com.example.missedcall;

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.CallLog;
import android.provider.CallLog.Calls;

/**
 *       ,     ,             
 * 
 * 
         :        
content://sms/inbox            
content://sms/sent            
content://sms/draft           
content://sms/outbox            
content://sms/failed             
content://sms/queued             

     Outbox       ,                 ,   。    
    sms       :    
_id                     , 1   
thread_id      ,      id   
address              
person                 ,    null 
date                 
protocol        ,  : 0 SMS_RPOTO, 1 MMS_PROTO  
read                0  , 1    
status            -1  ,0 complete, 64 pending, 128 failed 
type 
    ALL    = 0; 
    INBOX  = 1; 
    SENT   = 2; 
    DRAFT  = 3; 
    OUTBOX = 4; 
    FAILED = 5; 
    QUEUED = 6; 
body                          
service_center                
subject                        
reply_path_present     TP-Reply-Path 
locked
 * 
 * 
 * */
public class MissCall {
	
	/**
	 *         
	 * */
	public static int readMissCall(Context context) {
        int result = 0;
        Cursor cursor = context.getContentResolver().query(CallLog.Calls.CONTENT_URI, new String[] {
                Calls.TYPE
            }, " type=? and new=?", new String[] {
                    Calls.MISSED_TYPE + "", "1"
            }, "date desc");

        if (cursor != null) {
            result = cursor.getCount();
            cursor.close();
        }
        return result;
    }
	
	/**
	 *         
	 * */
	public static int getNewMmsCount(Context context) {
        int result = 0;
        Cursor csr = context.getContentResolver().query(Uri.parse("content://mms/inbox"),
                null, "read = 0", null, null);
        if (csr != null) {
            result = csr.getCount();
            csr.close();
        }
        return result;
    }
    
	/**
	 *         
	 * */
	public static int getNewSmsCount(Context context) {
        int result = 0;
        Cursor csr = context.getContentResolver().query(Uri.parse("content://sms"), null,
                "type = 1 and read = 0", null, null);
        if (csr != null) {
            result = csr.getCount();
            csr.close();
        }
        return result;
    }

}