2011-08-05 54 views

回答

1

上anddev

http://www.anddev.org/other-coding-problems-f5/miss-call-alert-in-android-t3959.html

編輯類似的問題:在意見中的要求

import java.text.DateFormat; 

import android.app.Activity; 
import android.database.Cursor; 
import android.os.Bundle; 
import android.provider.CallLog; 
import android.util.Log; 

public class CallLogActivity extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     String[] strFields = { 
       android.provider.CallLog.Calls.CACHED_NAME, android.provider.CallLog.Calls.NUMBER, 
       android.provider.CallLog.Calls.DATE, android.provider.CallLog.Calls.TYPE 
     }; 
     String strOrder = android.provider.CallLog.Calls.DATE + " DESC"; 

     Cursor mCallCursor = getContentResolver().query(android.provider.CallLog.Calls.CONTENT_URI, 
       strFields, null, null, strOrder); 

     if (mCallCursor.moveToFirst()) { 

      do { 

       boolean missed = mCallCursor.getInt(mCallCursor.getColumnIndex(CallLog.Calls.TYPE)) == CallLog.Calls.MISSED_TYPE; 

       if (missed) { 

        String name = mCallCursor.getString(mCallCursor 
          .getColumnIndex(CallLog.Calls.CACHED_NAME)); 

        String number = mCallCursor.getString(mCallCursor 
          .getColumnIndex(CallLog.Calls.NUMBER)); 

        String time = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG) 
          .format(mCallCursor.getLong(mCallCursor 
            .getColumnIndex(CallLog.Calls.DATE))); 

        Log.d("PhoneLog", "You have a missed call from " + name + " on " + number 
          + " at " + time); 
       } 

      } while (mCallCursor.moveToNext()); 

     } 

    } 
} 

確保您有

<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission> 
+0

thanks..is它可以顯示手機電話號碼誰錯過了電話? – wdyz

+0

http://developer.android.com/reference/android/provider/CallLog.Calls.html 顯示NUMBER,所以我會說是的 – dten

+0

嗯......我仍然不明白如何使用它..我的應用程序有聽衆檢查是否有來自1個電話號碼的misscall ..它會顯示吐司或記錄「你有錯過xxxx號碼的電話」。你能告訴我嗎?謝謝 – wdyz