2012-09-24 26 views
1

我想以編程方式將我的聯繫人從我的應用程序同步到本地Android聯繫人應用程序。請幫幫我。提前致謝。如何以編程方式將我們的應用聯繫人同步到Android上的本地聯繫人應用程序

+0

「我想從我的應用程序同步我的聯繫人......」你怎麼能在你的應用中的聯繫人? – Santhosh

+0

如果你有一些數字要存儲在聯繫人...這裏是答案.. http://stackoverflow.com/questions/4744187/how-to-add-new-contacts-in-android – Santhosh

+0

我必須同步我的聯繫人與我選擇的鈴聲 – AndroidRaji

回答

3

你可以試試下面的代碼帳戶同步

public static void requestSyncNow(final Context context) { 

    new Thread(new Runnable() { 
     @Override 
     public void run() { 
      AccountManager accountManager = AccountManager.get(context); 
      Account[] accounts = accountManager.getAccounts(); 
      boolean isMasterSyncOn = ContentResolver.getMasterSyncAutomatically(); 


      for (Account account : accounts) { 
       Log.d(TAG, "account=" + account); 

       int isSyncable = ContentResolver.getIsSyncable(account, 
         ContactsContract.AUTHORITY); 
       boolean isSyncOn = ContentResolver.getSyncAutomatically(account, 
         ContactsContract.AUTHORITY); 
       Log.d(TAG, "Syncable=" + isSyncable + " SyncOn=" + isSyncOn); 
       if (isSyncable > 0 /* && isSyncOn */) { 
        Log.d(TAG, "request Sync"); 
        Bundle bundle = new Bundle(); 
        bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); 
        ContentResolver.requestSync(account, ContactsContract.AUTHORITY, bundle); 
       } 
      } 

     } 
    }, "SyncLauncher").start(); 
} 
相關問題