通话记录完成后回调onQueryComplete方法,在调用startQuery时传入的第一个参数是CALL_LOG_TOKEN,所以此时case CALL_LOG_TOKEN满足,调用getNotificationInfo方法,将cursor中的信息构造一个NotificationInfo的实例,再次调用QueryHandler的startQuery方法查询通话记录是否存在对应的联系人信息,传入的第一个参数是CONTACT_TOKEN,
调用getNotificationInfo方法,将cursor中的信息构造一个NotificationInfo的实例
联系人信息查询完成后回调onQueryComplete方法,token是CONTACT_TOKEN,对于是一个默生的号码(通讯录人不存在对应的联系人信息)时直接调用notifyMissedCall方法在托盘显示未接来电通知,如果存在对应的联系人信息通过调ContactAsyncHelper的startObtainPhotoAsync
方法获取对应联系人的头像,QueryHandler
已实现了
ContactAsyncHelper
的
OnImageLoadCompleteListener接口,所以联系人头像加载完成后回调QueryHandler的onImageLoadComplete方法,
当联系人的头像加载完成后,回调onImageLoadComplete方法,最终调用notifyMissedCall方法在托盘中显示未接来电通知。
Android L 未接来电的处理
未接来电的处理逻辑由Android KK 版本的TeleService转移到Android L版本的Telecom中处理,但是在TeleService
中仍然保留了KK版本的NotificationMgr类的代码,但如Android KK版本对外的接口已经不存在了。
取消未接来电的通知
第三方的应用可以通过调用TelecomManager类的cancelMissedCallsNotification方法取消未接来电的消息通知,看到
cancelMissedCallsNotification的方法的命名应该感到很nice吧,这个就是将Android KK中TelephonyManager中移植过来的。
publicclass TelecomManager { ......
publicvoid cancelMissedCallsNotification(){
ITelecomService service = getTelecomService(); if(service !=null){ try{
service.cancelMissedCallsNotification(); }catch(RemoteException e){ } } } }
代码 x-x
TelecomManager调用TelecomServiceImpl的cancelMissedCallsNotification方法后,向内部的MainThreadHandler发送MSG_CANCEL_MISSED_CALLS_NOTIFICATION消息,处理此消息时调用了MissedCallNotifier的clearMissedCalls方法。
publicclass TelecomServiceImpl extends ITelecomService ...
publicvoid cancelMissedCallsNotification(){
enforceModifyPermissionOrDefaultDialer();
sendRequestAsync(MSG_CANCEL_MISSED_CALLS_NOTIFICATION,0); } }
privatefinalclass MainThreadHandler extends Handler { @Override
publicvoid handleMessage(Message msg){ if(msg.obj instanceof MainThreadRequest){
MainThreadRequest request =(MainThreadRequest) msg.obj; Object result =null; switch(msg.what){ .......
caseMSG_CANCEL_MISSED_CALLS_NOTIFICATION:
mMissedCallNotifier.clearMissedCalls(); break;
....... } }
} }
代码 x-x
MissedCallNotifier的clearMissedCalls做了两件事件:
? 将通话记录数据库中的未接来电记录的未读状态变更为已读状态; ? 清除在通知栏中的通知;
通话记录未接来电的未读状态->已读状态,通过一个多线程异步任务的方法更新通话记录的provider。
publicclass MissedCallNotifier {
....
/** Clears missed call notification and marks the call log's missed calls as read. */ void clearMissedCalls(){
AsyncTask.execute(new Runnable(){ @Override publicvoid run(){
// Clear the list of new missed calls from the call log. try{
ContentValues values =new ContentValues(); values.put(Calls.NEW,0);
values.put(Calls.IS_READ,1);
StringBuilder where =new StringBuilder(); where.append(Calls.NEW); where.append(\); where.append(Calls.TYPE); where.append(\);
mContext.getContentResolver().update(Calls.CONTENT_URI, values, where.toString(), new String[]{ Integer.toString(Calls.MISSED_TYPE)}); }catch(Exception e){
e.printStackTrace();
Log.e(\, e,\); } } });
cancelMissedCallNotification();
}
... }
代码 x-x
接着调用cancelMissedCallNotification方法,内部通过调用NotificationManager的cancel方法清除通知栏中的未接来电notification,并将未接来电计数器mMissedCallCount重置为0。
publicclass MissedCallNotifier {
....
/** Cancels the \ privatevoid cancelMissedCallNotification(){ // Reset the number of missed calls to 0. mMissedCallCount =0;
mNotificationManager.cancel(MISSED_CALL_NOTIFICATION_ID); }
... }
代码 x-x
相关推荐: