Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
308 views
in Technique[技术] by (71.8m points)

notifications - How to retrieve missed calls on Android SDK 2.2

in my app I should do some action when a call comes but not answered by the user.

I have searched in the android.telephony and the NotificationManager, but I haven't found a method to solve this problem.

Does someone have an idea of how to get to know if there is a missed call on the phone or not ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here is code that can query the call log for a missed call. Basically, you will have to trigger this somehow and make sure that you give the call log some time ( a few seconds should do it) to write the information otherwise if you check the call log too soon you will not find the most recent call.

final String[] projection = null;
final String selection = null;
final String[] selectionArgs = null;
final String sortOrder = android.provider.CallLog.Calls.DATE + " DESC";
Cursor cursor = null;
try{
    cursor = context.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 isCallNew = cursor.getString(cursor.getColumnIndex(android.provider.CallLog.Calls.NEW));
        if(Integer.parseInt(callType) == MISSED_CALL_TYPE && Integer.parseInt(isCallNew) > 0){
            if (_debug) Log.v("Missed Call Found: " + callNumber);
        }
    }
}catch(Exception ex){
    if (_debug) Log.e("ERROR: " + ex.toString());
}finally{
    cursor.close();
}

I hope you find this useful.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...