如何找回在Android SDK 2.2未接来电 [英] 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.
我有搜索在 android.telephony 的和的 NotificationManager 的,但我还没有找到一个方法来解决这个问题。
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 ?
推荐答案
下面是code,可以查询通话记录的未接来电。基本上,你将不得不以某种方式引发这一点,并确保你给通话记录一段时间(几秒钟应该这样做)以其他方式写入信息,如果你太早查看通话记录,你不会找到最近调用。
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.
这篇关于如何找回在Android SDK 2.2未接来电的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!