在我的应用程序中,当来电但用户未接听时,我应该采取一些措施。
我在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提供程序(或者可能是 CallLog.Calls),此页面说明了如何查询内容提供程序:http: //developer.android.com/guide/topics/providers/content-providers。 html#基础
如果你能完成这项工作,我会很高兴看到代码!
我想您有内容提供商可以访问通话记录。
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 来发现手机恢复正常状态并访问通话记录......
可能重复