您的位置:首页 > 移动开发 > Android开发

Android 不能同步Facebook联系人

2013-11-07 11:55 417 查看


FaceBook Sync for Android ICS Devices [ Updated Aug 01 '12 ]

May
29, 2012Androidandroid, facebook, tweaks

— 转自:http://niranjanthilak.com/facebook-sync-for-android-ics-devices/

If you are one of the unlucky ones who can’t make the original Facebook Application to sync its contacts with your phone / Google contacts on Custom ROMs such as AOKP , ( CyanogenMod ) CM9 or MIUI . This solution
is the solution for you. It ‘will make the original FB application Sync it’s contacts with the Contacts app. I’ve created a flashable zip method using CWM and another one using ADB+Windows as well.

This will enable Sync dialog on the original Facebook application , just like it used to do on Gingerbread.







Update [Aug 1] : Files Updated.

Based on MIUI 2.7.27 , CM9 2012-07-31 & AOKP]MileStone 6
Update ->I won’t be able to update the files weekly anymore. But i will try to update them whenever i can get them to be updated.
Files are available at the bottom of this post.
Read the instructions if you don’t want to see a lot of FC’s popping up.

Note:

If the Contact Pictures are not loading, give it some time and keep the contacts application on with internet connected. It is slow , and it is because
of slow FB servers.
If this whole thing leaves you into a bootloop ( very unlikely ) or lot of FC’s ( very much likely if you didn’t reboot / if you flashed the wrong zip ) , You can reflash your current ROM to fix it. Eg: If you were on the CM9 2012-07-31 ,
flash the CM9 2012-07-31.zip again over your phone. No need to wipe and no need to format to revert this -hack- back.

PreRequisites

You should have ClockWorkMod ( CWM ) Recovery in your phone for doing it via Method#1.
You should be having atleast one account or phone number in the phone book , This is to ensure that contacts database is intialized. So -DO NOT- flash this directly after wiping
or installing a new ROM, do it after a boot.


Method#1 Using ClockWorkMod Recovery

Files : Download the corresponding file from below( Filenames have date and ROM mentioned)

Steps:

Copy the appropriate ZIP file for your phone/ROM to your SD card.
Reboot your phone to recovery mode . You will need ClockWorkMod Recovery 3+ for this tweak to work.
Go to ‘Mounts and Storage’. Mount ‘data’ ( and ‘datadata’ if it is present ). This step is very important.
Choose update from sdcard.
Locate the ZIP file and update it.
Reboot.
Add FB account ( FB accounts which you had added before wont sync properly, so delete it and add again).
Sync it.


Method#2 - Using Windows+ADB .

Files : Download the corresponding file from below( Filenames have date and ROM mentioned)

Download the ‘FBSync_ADB_xx’ zip file corresponding to your ROM.
Extract it to a folder. For eg: to your desktop.
Connect your phone in debug mode. ( You can enable debugging mode from your phone Under Development > Enable Debugging mode ) .
Run patch_db.cmd with administrator privileges ( this is a must if you have UAC enabled ). For this, Right click ‘patch_db.cmd’ and select ‘Run as Administrator’
Reboot the phone.


Warning

If you wipe the phone/contacts, you will have to flash the zip again.
Flash it after booting it once onto your phone and adding an account other than FB, preferably. This is to ensure that the database has been created. If you already have accounts , clear them , leave one phone contact preferably.
I’m not responsible for any data loss. If you mismatch the ROM and ZIP then it’s bound to soft-crash the phone.


Detailed Explanation:

Facebook application can sync its contacts with the Contacts ( Through ContactsProvider ) only when its whitelisted ( or, in other words , given an escalated permission set ) in the ROM.
For this , You have to edit the ContactsProvider.apk and add the whitelisted permission.
For editing the ContactsProvider.apk ( Which resides in the /system/app/ directory) ,You will need smali
( An assembler/disassembler for Android’s dex format ).
After disassembling the ContactsProvider.apk using smali , Go to the res/values/ folder ( in the disassembled source ) , and add the file ( arrays.xml ) containing the following content:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<string-array name="unrestricted_packages">
<item>com.facebook.katana</item>
</string-array>
</resources>


The com.facebook.katana is the application of facebook. So after adding the arrays.xml file to the /res/values/ folder, Assemble the ContactsProvider using the smali into an unsigned apk file.
Now , Since ICS , Android 4.0 , Google has disabled this provision of whitelisting applications natively , hence they have obfuscated certain fields from the database.
Add the column named
is_restricted

to the raw_contacts table inside contacts2.db ( stored in /data/data/com.android.providers.contacts/database/ )

If you have sqlite enabled ( along with busybox ) in your kernel you can use this command for altering the database and adding the necessary field by running it under ADB Shell:
sqlite3 /data/data/com.android.providers.contacts/databases/contacts2.db
'ALTER TABLE raw_contacts ADD COLUMN is_restricted VARCHAR';


After adding the column, all the facebook accounts added will be provided with Sync Prompt and they will appear under contacts.

经实测,按 Detailed
Explanation 方法成功实现。

直接上图:

修改前: 修改后:



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: