2012-01-06 41 views
-1

安裝我的應用程序後(但尚未啓動),是否有任何方法可以自動添加帳戶?安裝應用程序後自動添加帳戶

+1

你需要更具體的你正在嘗試做的。 http://blog.stackoverflow.com/2010/10/asking-better-questions/ – 2012-01-06 13:53:30

回答

3

這是不可能的什麼「剛剛安裝我的應用程序(但它尚未啓動)」。當用戶啓動您的主要活動時,您可以設置該帳戶或任何您想要的其他類型的首次活動。

2

這裏是一個代碼和平自動激活賬戶

final AccountManager accountManager = AccountManager.get(this); 
    String authority = getString(R.string.acc_authority); 
    String accountType = getString(R.string.acc_name); 
    String accountName = getString(R.string.app_name); 

    Account[] existingAccs = accountManager.getAccountsByType(accountType); 
    if (existingAccs.length > 0) { 
     return; 
    } 

    Account account = new Account(accountName, accountType); 
    if (accountManager.addAccountExplicitly(account, null, null)) { 
     ContentResolver.setIsSyncable(account, authority, 1); 
     ContentResolver.setSyncAutomatically(account, authority, true); 
     ContentResolver.requestSync(account, authority, new Bundle()); 
     ContentResolver.addPeriodicSync(account, authority, new Bundle(), 60*10); 
    } 
+0

目前安裝我的應用程序和登錄後,我必須去帳戶啓用同步。默認情況下關閉。有什麼方法可以設置默認值嗎? – ray 2013-06-18 17:57:02

相關問題