Is it possible to override the Accounts & Sync 'Remove Account' functionality
Asked Answered
D

2

8

I am working on application which has a sync adapter and authenticator used to add accounts via the Android Account Manager. I've got the following two problems:

1) It was possible to override the 'Add Account' button's functionality in Accounts & Sync, but I can't find a way to override the 'Remove Account' button's functionality - is this possible?

2) I've read that authenticators can prevent removal of their accounts but I can't find out how...does anyone know how I can add this to my authenticator? That way I might be able to use AbstractAccoutnAuthenticator.getAccountRemovalAllowed to acheive the functionality I want.

Thanks

Desiderata answered 23/3, 2012 at 15:4 Comment(0)
M
8

To answer your second question:

Assuming your package name is com.companyname

Create an Authenticator class that extends AbstractAccountAuthenticator in the package com.companyname.auth and implement this method on it:

@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;
}

Add this to the manifest:

    <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>

(Note that lint gives a warning that this exported service does not require permissions).

And then in res/xml add the authenticator.xml file:

<?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" />

Assuming that your account type is "com.companyname". That's what we do and it appears to be working from API 8 on up.

Malkin answered 22/5, 2012 at 17:58 Comment(0)
J
1

The previous user is right. However there is NO way to customize the dialog (the documentation lies and says you can return an intent for a custom screen, which is clearly not implemented in the code).

Returning false is NOT recommended though. Since it returns a dialog that says something very scary to the user (something along the lines that you need to do a factory reset)

Jumbala answered 28/7, 2012 at 4:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.