private
void
readMissedCallAPI() {
     
     
final
String[] projection = null;
   
 final
String selection = null;
   
 final
String[] selectionArgs = null;
   
 final
String sortOrder  = android.provider.CallLog.Calls.DATE
+ " DESC";
   
 Cursor cursor   = null;
   
 int
MISSED_CALL_TYPE = android.provider.CallLog.Calls.MISSED_TYPE;
   
 try{
   
  cursor =
getApplicationContext().getContentResolver().query(
     
           Uri.parse("content://call_log/calls"),
     
           projection,
     
           selection,
     
           selectionArgs,
     
           sortOrder);
     
   while
(cursor.moveToNext()) { 
     
       String callLogID =
cursor.getString(cursor.getColumnIndex(android.provider.CallLog.Calls._ID));
     
       String callNumber  =
cursor.getString(cursor.getColumnIndex(android.provider.CallLog.Calls.NUMBER));
     
       String callDate
 =
cursor.getString(cursor.getColumnIndex(android.provider.CallLog.Calls.DATE));
     
       String callType  =
cursor.getString(cursor.getColumnIndex(android.provider.CallLog.Calls.TYPE));
     
       String callNew  =
cursor.getString(cursor.getColumnIndex(android.provider.CallLog.Calls.NEW));
     
       if(Integer.parseInt(callType)
== MISSED_CALL_TYPE && Integer.parseInt(callNew)
> 0){
     
           Log.v("bharath",
"Missed Call Found: "
+ callNumber);
     
       }
     
   }
   
 }catch(Exception
ex){
      
Log.v("bharath",
"ERROR: "
+ ex.toString());
   
 }finally{
     
   cursor.close();
     }
}
Note:
don't forget to add android.permission.READ_CONTACTS in Androidmainfest.xml
Note:
don't forget to add android.permission.READ_CONTACTS in Androidmainfest.xml
 
 
 
1 comment:
how can i get only last missed call number or name??????????
Post a Comment