Android:通过编程更新的联系人与其他应用程序不同步。
创始人
2024-10-13 19:30:49
0

问题描述:

在Android应用程序中通过编程更新了联系人信息(例如姓名、电话号码等),但是这些更新与其他应用程序(例如联系人应用程序、电话应用程序等)不同步。这可能导致在其他应用程序中无法看到最新的联系人信息。

解决方法:

  1. 通过ContentProvider更新联系人信息
ContentResolver resolver = getContentResolver();
ContentValues values = new ContentValues();
values.put(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, "John Doe");
values.put(ContactsContract.CommonDataKinds.Phone.NUMBER, "1234567890");

String where = ContactsContract.Data._ID + " = ?";
String[] selectionArgs = new String[]{contactId}; // 要更新的联系人的ID

resolver.update(ContactsContract.Data.CONTENT_URI, values, where, selectionArgs);
  1. 发送联系人更新广播
Intent intent = new Intent(Intent.ACTION_PROVIDER_CHANGED);
intent.setData(ContactsContract.Contacts.CONTENT_URI);
sendBroadcast(intent);
  1. 强制同步联系人数据
AccountManager accountManager = AccountManager.get(this);
Account[] accounts = accountManager.getAccountsByType("com.google");
for (Account account : accounts) {
    Bundle extras = new Bundle();
    extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
    extras.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
    ContentResolver.requestSync(account, ContactsContract.AUTHORITY, extras);
}

请注意,上述解决方法仅适用于使用ContactsContract API更新联系人信息的情况。如果您使用的是其他联系人管理库或自定义的联系人存储方式,则需要根据具体情况进行相应的修改和处理。

相关内容

热门资讯

最新技巧!wepoker私人局... 最新技巧!wepoker私人局俱乐部,wepoker怎么提高运气,细节揭秘(有挂方法)科技教程也叫必...
盘点一款!hhpoker有辅助... 盘点一款!hhpoker有辅助吗,德普辅助软件,辅助教程(有挂辅助)1、许多玩家不知道hhpoker...
揭秘攻略!hhpoker有辅助... 揭秘攻略!hhpoker有辅助吗,德普辅助软件,攻略教程(有挂方法);玩家必备必赢加哟《136704...
发现一款!hhpoker德州挂... 这是一款非常优秀的hhpoker德州挂真的有吗 ia辅助检测软件,能够让你了解到hhpoker德州挂...
攻略讲解!wepoker正确养... 攻略讲解!wepoker正确养号方法,黑侠破解wepoker,安装教程(有挂神器);人气非常高,ai...
最新技巧!wepoker模拟器... 最新技巧!wepoker模拟器哪个,约局吧如何查看是否有挂,透明教程(有挂攻略);科技安装教程;13...
今日公布!hhpoker是正品... 今日公布!hhpoker是正品吗,红龙poker辅助工具,教你攻略(有挂技巧)科技教程也叫必备教程,...
推荐攻略!红龙poker辅助平... 推荐攻略!红龙poker辅助平台,wepoker怎么设置透视,解密教程(有挂神器)科技教程也叫必备教...
玩家必备攻略!aapoker ... 玩家必备攻略!aapoker ai插件,红龙poker辅助工具,切实教程(有挂技巧)科技教程也叫必备...
玩家必看教程!werplan有... 自定义wepoker俱乐部辅助系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克专用辅助...