【发布时间】:2010-09-24 09:23:50
【问题描述】:
在我的应用程序中,当来电但用户未接听时,我应该执行一些操作。
我已经在android.telephony和NotificationManager中进行了搜索,但是我没有找到解决这个问题的方法。
有人知道如何知道电话上是否有未接电话吗?
【问题讨论】:
标签: android notifications telephony
在我的应用程序中,当来电但用户未接听时,我应该执行一些操作。
我已经在android.telephony和NotificationManager中进行了搜索,但是我没有找到解决这个问题的方法。
有人知道如何知道电话上是否有未接电话吗?
【问题讨论】:
标签: android notifications telephony
这是可以查询未接电话的通话记录的代码。基本上,您必须以某种方式触发它,并确保您给通话记录一些时间(应该几秒钟)来写入信息,否则如果您过早检查通话记录,您将找不到最近的通话。
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 提供程序(或者可能是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
一旦您收到此通知,请设置一个计时器或使用一些内置 Intents 来发现手机恢复正常状态并访问通话记录...
可能重复
【讨论】: