解决:HotSeat短信图标提醒有误

【操作步骤】正常收发短信、彩信。

【测试结果】所有短信均已阅读,但在HOME界面的短信图标仍提示有一条短信未读。重启后仍存在。

经过分析,导致该情况的主要原因为当彩信已读的时候,launcher中进行查询的语句有问题。因为当彩信的状态为已读后pdu表中的read字段的值会由0变为1,而彩信点击进行下载,下载成功后信息类型由130变为132.我们可以到处数据表进行下一步分析。


现在我们从数据库表中的数据进行分析,分析前我们需要解释一下,read的值为0表示未读,为1表示已读,m_type的值为130表示未下载,为132表示已下载。

我们从数据库表中可以看到当前信息状态全部为已读,而m_type中值为130的为条数为8条,132的值为2条,也就是说当前有8条彩信息未进行下载。按照正常的逻辑来说,在hotseat中不应该存在未读消息的提醒,但是在hotseat中提示未读消息为8条。因此我们断定该问题有查询语句所导致。我们找到launcher应用下Launcher.java中的相关方法进行分析:

private void updateDecorate(int whichIcon,ShortcutInfo info){

    final ArrayList<ShortcutInfo> shortcuts = new ArrayList<ShortcutInfo>();
    if(info != null){
        shortcuts.add(info);
    }

    getTargetShortcuts(whichIcon == UPDATE_MMS_ICON ? "com.android.mms" : "activities.DialtactsActivity",shortcuts);

    if(shortcuts.size() == 0){
        return;
    }

    new AsyncTask<Integer,Void,Integer>(){
        @Override
        protected Integer doInBackground(Integer... whichIcon){

            int count = 0;

            switch(whichIcon[0]){
                case UPDATE_MMS_ICON:
                    Cursor mmsCursor = getContentResolver().query(Uri.parse("content://mms/inbox"),
                            null,"m_type = 128 or m_type = 130 or m_type = 132 and read = 0",null,null);
                    if(mmsCursor != null){
                        count += mmsCursor.getCount();
                        mmsCursor.close();
                    }
                    Cursor smsCursor = getContentResolver().query(Uri.parse("content://sms"),null,"type = 1 and read = 0",null,null);
                    if(smsCursor != null){
                        count += smsCursor.getCount();
                        smsCursor.close();
                    }
                    break;
                case UPDATE_PHONE_ICON:

                    Cursor cursor = getContentResolver().query(Calls.CONTENT_URI,new String[]{
                                    Calls.NUMBER,Calls.TYPE,Calls.NEW},null,null,Calls.DEFAULT_SORT_ORDER);
                    if(cursor != null){
                        while(cursor.moveToNext()){
                            if((cursor.getInt(cursor.getColumnIndex(Calls.TYPE)) == Calls.MISSED_TYPE)
                                    && (cursor.getInt(cursor.getColumnIndex(Calls.NEW)) == 1)){
                                count++;
                            }
                        }
                        cursor.close();
                    }
                    break;
                default:
                    this.cancel(true);
                    break;
            }

            return count;
        }

        @Override
        protected void onPostExecute(Integer result){
            if(result != 0){
                for(ShortcutInfo shortcut : shortcuts){
                    if(shortcut.view != null){
                        shortcut.view.decorateIcon(String.valueOf(result));
                    }
                }
            } else{
                for(ShortcutInfo shortcut : shortcuts){
                    if(shortcut.view != null){
                        shortcut.view.clearDecorate();
                    }
                }
            }
        }
    }.execute(whichIcon);
}

上述代码中为原始代码,加粗标红的代码为查询语句的where子句部分,我们如果对数据库了解的话,我们会发现这里的优先级有个问题,因此我们做出修改,问题如下:、

"(m_type = 128 or m_type = 130 or m_type = 132 )and read = 0"

问题迎刃而解。


原文地址:https://www.cnblogs.com/bill-technology/p/4130844.html