2012-03-23 65 views
7

我正在使用具有同步適配器和身份驗證器的應用程序,該應用程序用於通過Android帳戶管理器添加帳戶。我有以下兩個問題:是否有可能覆蓋帳戶和同步「刪除帳戶」功能

1)可以重寫帳戶&同步中的「添加帳戶」按鈕的功能,但我找不到重寫「刪除帳戶」按鈕的功能的方法 - 這可能嗎?

2)我讀過認證可以防止刪除他們的帳戶,但我不知道如何...有人知道我可以如何將其添加到我的authenticator嗎?這樣我可以使用AbstractAccoutnAuthenticator.getAccountRemovalAllowed來獲得我想要的功能。

感謝

回答

7

要回答你的第二個問題:

假設你的包名是com.companyname

創建的包com.companyname.auth延伸AbstractAccountAuthenticator一個Authenticator類,並實現該方法它:

@Override 
public Bundle getAccountRemovalAllowed(AccountAuthenticatorResponse response, Account account) { 
    Bundle result = new Bundle(); 
    boolean allowed = false; // or whatever logic you want here 
    result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, allowed); 
    return result; 
} 

一下添加到清單:

<service android:name=".auth.AuthenticationService"> 
     <intent-filter> 
      <action android:name="android.accounts.AccountAuthenticator"></action> 
     </intent-filter> 
     <meta-data android:name="android.accounts.AccountAuthenticator" android:resource="@xml/authenticator"></meta-data> 
    </service> 

(請注意,lint會提示此導出的服務不需要權限)。

然後在res/XML添加authenticator.xml文件:

<?xml version="1.0" encoding="utf-8"?> 
<account-authenticator 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:accountType="com.companyname" 
android:icon="@drawable/app_icon" 
android:smallIcon="@drawable/app_icon_small" 
android:label="@string/app_name" /> 

假設你的帳戶類型是 「com.companyname」。這就是我們所做的,它似乎是從API 8起。

1

上一個用戶是正確的。然而,沒有辦法自定義對話框(文檔在說謊,並說你可以返回一個自定義屏幕的意圖,這在代碼中顯然沒有實現)。

雖然不推薦返回false。由於它返回一個對話框,用於說明用戶非常可怕的事情(沿線需要做出廠重置)

相關問題