美文网首页
联系人存储位置相关问题

联系人存储位置相关问题

作者: 酥脆海苔饼干 | 来源:发表于2017-06-06 14:01 被阅读0次

    1.联系人存储位置
    ContactEditorFragment.java
    onActivityCreated在account为空时进入selectAccountAndCreateContact方法.
    <pre>
    private void selectAccountAndCreateContact() {
    if (mNewLocalProfile) {
    createContact(null);
    return;
    }
      //跳转到 ContactEditorAccountsChangedActivity出现选择界面
    if (mEditorUtils.shouldShowAccountChangedNotification() &&
    !mContext.getResources().getBoolean(R.bool.def_storage_behavior_enabled)) {
    Intent intent = new Intent(mContext, ContactEditorAccountsChangedActivity.class);
    mStatus = Status.SUB_ACTIVITY;
    startActivityForResult(intent, REQUEST_CODE_ACCOUNTS_CHANGED);
    } else {
    AccountWithDataSet defaultAccount = mEditorUtils.getDefaultAccount();
    if (defaultAccount == null) {
    createContact(null);
    } else {
    createContact(defaultAccount);
    }
    }
    }
    </pre>
    ContactEditorAccountsChangedActivity.java
    onCreate方法:
    <pre>
     if (numAccounts >= 2) {
    setContentView(R.layout.contact_editor_accounts_changed_activity_with_picker);

            final TextView textView = (TextView) findViewById(R.id.text);
            textView.setText(getString(R.string.contact_editor_prompt_multiple_accounts));
    
            final TextView button = (TextView) findViewById(R.id.add_account_button);
            button.setText(getString(R.string.add_new_account));
            button.setOnClickListener(mAddAccountClickListener);
    
            final ListView accountListView = (ListView) findViewById(R.id.account_list);
    

    //可选择存储位置
    mAccountListAdapter = new AccountsListAdapter(this,
    AccountListFilter.ACCOUNTS_CONTACT_WRITABLE);
    accountListView.setAdapter(mAccountListAdapter);
    accountListView.setOnItemClickListener(mAccountListItemClickListener);
    }
    </pre>
    AccountsListAdapter.java
    getView方法:
         text1.setText(accountType.getDisplayLabel(mContext, account.name));
    AccountType.java
    getDisplayLabel方法:
    <pre>
    public CharSequence getDisplayLabel(Context context) {
    CharSequence label = null;
    updateAuthDescriptions(context);
    if (mTypeToAuthDescription.containsKey(accountType)) {
    try {
    AuthenticatorDescription desc = mTypeToAuthDescription.get(accountType);
                    //desc为多个type下的type=com.android.localphone
    Context authContext = context.createPackageContext(desc.packageName, 0);
                   //desc.packageName为com.qualcomm.simcontacts
    label = authContext.getResources().getText(desc.labelId);
    } catch (PackageManager.NameNotFoundException e) {
    Log.w(TAG, "No label name for account type " + accountType);
    } catch (Resources.NotFoundException e) {
    Log.w(TAG, "No label icon for account type " + accountType);
    }
    }
    return label;
    }
    </pre>
      因此根据context.createPackageContext(要创建的包名,参数)自身方法,在创建另一个包的上下文,然后通过getResources().getText取其资源;
      在高通项目中,com.qualcomm.simcontacts包名文件所在目录为vendor/qcom/proprietary/trlrphony-apps/simContacts;其中上面log打印出来的type在该目录下
    <pre>
    res/xml/phone_authenticator.
    <account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
    android:accountType="com.android.localphone"
    android:icon="@drawable/ic_phone"
    android:smallIcon="@drawable/ic_phone"
    android:label="@string/account_phone"
    />
    </pre>
    显示ladbel字串目录为vendor/qcom/proprietary/qrdplus/globalization/multi-language/res-overlay/vendor/qcom/proprietary/telephony-apps/SimContacts/res
    2.关于AuthenticatorDescription的学习总结
      联系人数据库中包含有rawContacts数据表,其中accountType以及accountName用于存储账号类型及账号名称。上文中获取的com.android.localphone为所存储的accountType
      其中AuthenticatorDescription用于保存账号类型的描述资源,从而实现国际化的描述。(参考文章:http://m.blog.csdn.net/article/details?id=14447143)

    相关文章

      网友评论

          本文标题:联系人存储位置相关问题

          本文链接:https://www.haomeiwen.com/subject/peigfxtx.html