我从Phonestatelistener知道,我们会知道,呼叫类型如传入,或振铃或挑选等。但一旦呼叫结束,即一旦电话达到空闲状态,我想知道什么是呼叫状态,是它选择,错过或拒绝
接听,+ 91123456789是来电,通话结束后,该号码将作为未接来电存储在电话通话记录中,
有没有办法从特定号码+91123456789的通话记录中获取最近的状态,是否可能?
答案 0 :(得分:2)
以下是可以查询未接来电的通话记录的代码。基本上,你必须触发这个并确保你给通话记录一些时间(几秒钟就应该这样做)来写信息,否则如果你太早检查通话记录你将找不到最近的通话。 / p>
int MISSED_CALL_TYPE = android.provider.CallLog.Calls.MISSED_TYPE
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);
cursor = getContentResolver().query(CallLog.Calls.CONTENT_URI, null, CallLog.Calls.NUMBER + "=? ", yourNumber, 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);
break ;
}
}
}catch(Exception ex){
if (_debug) Log.e("ERROR: " + ex.toString());
}finally{
cursor.close();
}
我希望你发现这很有用,就像你可以获得其他状态一样。
在清单中添加此权限 android.permission.READ_CONTACTS