第一范文网 - 专业文章范例文档资料分享平台

NoticationMgr对于未接来电的处理

来源:用户分享 时间:2025/5/20 3:49:49 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

通话记录完成后回调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

搜索更多关于: NoticationMgr对于未接来电的处理 的文档
NoticationMgr对于未接来电的处理.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c4b3v18nil635m4y30v08_2.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top