Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/190.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 是否可以覆盖帐户&;同步';删除帐户';功能_Android_Accountmanager_Accounts - Fatal编程技术网

Android 是否可以覆盖帐户&;同步';删除帐户';功能

Android 是否可以覆盖帐户&;同步';删除帐户';功能,android,accountmanager,accounts,Android,Accountmanager,Accounts,我正在开发一个应用程序,它有一个同步适配器和验证器,用于通过Android帐户管理器添加帐户。我有以下两个问题: 1) 可以在Accounts&Sync中覆盖“Add Account”(添加帐户)按钮的功能,但我找不到覆盖“Remove Account”(删除帐户)按钮功能的方法-这可能吗 2) 我已经读到,验证器可以阻止删除他们的帐户,但我不知道如何…有人知道我可以如何将此添加到我的验证器吗?这样我就可以使用AbstractAccountNauthenticator.getAccountRem

我正在开发一个应用程序,它有一个同步适配器和验证器,用于通过Android帐户管理器添加帐户。我有以下两个问题:

1) 可以在Accounts&Sync中覆盖“Add Account”(添加帐户)按钮的功能,但我找不到覆盖“Remove Account”(删除帐户)按钮功能的方法-这可能吗

2) 我已经读到,验证器可以阻止删除他们的帐户,但我不知道如何…有人知道我可以如何将此添加到我的验证器吗?这样我就可以使用AbstractAccountNauthenticator.getAccountRemovalAllowed实现我想要的功能


感谢您回答第二个问题:

假设您的包名为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开始工作的。

前面的用户是对的。但是,没有办法自定义对话框(文档中说您可以返回自定义屏幕的意图,这显然没有在代码中实现)

但不建议返回false。因为它返回一个对话框,对用户说了一些非常可怕的话(类似于你需要重置出厂设置的话)