在我的应用中,当用户未接来电时,我需要执行某些操作。
我已经在android.telephony和NotificationManager中搜索过,但没有找到解决这个问题的方法。
有人知道如何判断手机上是否有未接来电吗?
在我的应用中,当用户未接来电时,我需要执行某些操作。
我已经在android.telephony和NotificationManager中搜索过,但没有找到解决这个问题的方法。
有人知道如何判断手机上是否有未接来电吗?
这里是可以查询未接来电通话记录的代码。基本上,您将不得不以某种方式触发它,并确保给通话记录一些时间(几秒钟足够了)来写入信息,否则如果您过早地检查通话记录,则找不到最近的通话。
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();
}
我希望你会觉得这有用。
从我的理解来看,您需要查询通话记录提供者(或者可能是CallLog.Calls),而这个页面解释了如何查询内容提供者:http://developer.android.com/guide/topics/providers/content-providers.html#basics
如果您能让它工作,我很高兴看到代码!
我想你应该有内容提供者来访问通话记录。
http://www.anddev.org/video-tut_-_querying_and_displaying_the_calllog-t169.html
http://www.devx.com/wireless/Article/41133
如果这段代码能够正常工作,你只需要在正确的时间运行这个查询。我的意思是检查一些样本,当你的设备接到电话时可以通知你。http://groups.google.com/group/android-developers/browse_thread/thread/d97a759a3708cbe3
一旦您收到此通知,请设置一个计时器或使用一些内置的意图来查找手机是否恢复正常状态并访问通话记录...
可能是重复的问题