首页 > 代码库 > 解决:更改短信中心号码不能及时更新显示

解决:更改短信中心号码不能及时更新显示

【测试步骤】:
1、进入短信界面
2、菜单-设置
3、修改短信中心号码(Set the SIM‘s smsc number) 保存
【测试结果】:提示保存成功,但是号码没有改变,退出重新进入设置才会看到号码更新

【预期结果】:提示保存成功,号码变为修改过的号码

相关Activity:通过Logcat中I/ActivityManager(  896):我们可以定位到该类-MessagingPreferenceActivity;

相关控件:mSmscPrefList.add(pref);

根据分析我们发现在MessagingPreferenceActivity的registerReceiver()方法中动态注册了广播接收器对设置短信中心号码的写卡操作进行监听,但是在写卡成功后并没有对页面中短信中心号码进行更新,因此我们添加以下代码(红色+加粗部分)为添加代码。

 private void registerReceiver() {
        if (mReceiver != null) return;
        mReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                String action = intent.getAction();
                if (Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(action)) {
                    updateSMSCPref(ALL_SUB, isAirplaneModeOn());
                    Message msg = new Message();
                    msg.what = AIR_PLANE_MODE_CHANGED;
                    msg.arg1 = (isAirplaneModeOn() ? AIR_PLANE_MODE_ENABLE : AIR_PLANE_MODE_DISABLE);
                    mAirPlaneModeHandler.sendMessage(msg);
                /*AddBy:yabin.huang BugID:SWBUG00029352 Date:20140521*/
                } else if(TelephonyIntents.ACTION_SIM_STATE_CHANGED.equals(action)){
                    if(isSimReady())
                    updateSMSCPref(ALL_SUB, isAirplaneModeOn());
                } else if (NOTIFY_SMSC_ERROR.equals(action)) {
                    showToast(R.string.set_smsc_error);
                } else if (NOTIFY_SMSC_SUCCESS.equals(action)) {
                    showToast(R.string.set_smsc_success);
                    int sub = intent.getIntExtra(SUB, 0);
                    String summary = intent.getStringExtra(SMSC);

                    Log.d("bill","summary--"+summary);
                    mSmscPrefList.get(sub).setSummary(summary);
                } else if (NOTIFY_SMSC_UPDATE.equals(action)) {
                    int sub = intent.getIntExtra(SUB, 0);
                    if(TextUtils.isEmpty(mSmscPrefList.get(sub).getSummary())){
                        String summary = intent.getStringExtra(SMSC);
                        if(summary==null||summary.length()==0){
                            updateSMSCPref(ALL_SUB, isAirplaneModeOn());
                            mSmscPrefList.get(sub).setEnabled(false);
                            mSmscPrefList.get(sub).setSummary(null);
                        }else{
                            mSmscPrefList.get(sub).setEnabled(true);
                            mSmscPrefList.get(sub).setSummary(summary);
                        }
                    }else{
                        mSmscPrefList.get(sub).setEnabled(true);
                    }
                }
            }
        };

        IntentFilter filter = new IntentFilter();
        /*AddBy:yabin.huang BugID:SWBUG00029352 Date:20140521*/
        filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
        filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED);
        filter.addAction(NOTIFY_SMSC_ERROR);
        filter.addAction(NOTIFY_SMSC_SUCCESS);
        filter.addAction(NOTIFY_SMSC_UPDATE);
        registerReceiver(mReceiver, filter);
    }