Android:如何从“帐户和同步”下显示的数据库中删除帐户来自我自己的申请

发布于 2024-09-11 03:09:04 字数 1269 浏览 3 评论 0原文

如何从“帐户和同步”中删除 Google 帐户?我试图将此行称为我的应用程序:

AccountManagerService.getSingleton().onServiceChanged(null,true);

而 onServiceChanged() 方法是在 AccountManagerService.java 中定义的。

public void onServiceChanged(AuthenticatorDescription desc, boolean removed) {
    boolean accountDeleted = false;
    SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    Cursor cursor = db.query(TABLE_ACCOUNTS,
            new String[]{ACCOUNTS_ID, ACCOUNTS_TYPE, ACCOUNTS_NAME},
            ACCOUNTS_TYPE + "=?", new String[]{desc.type}, null, null, null);
    try {
        while (cursor.moveToNext()) {
            final long accountId = cursor.getLong(0);
            final String accountType = cursor.getString(1);
            final String accountName = cursor.getString(2);
            Log.d(TAG, "deleting account " + accountName + " because type "
                    + accountType + " no longer has a registered authenticator");
            db.delete(TABLE_ACCOUNTS, ACCOUNTS_ID + "=" + accountId, null);
            accountDeleted = true;
        }
    } finally {
        cursor.close();
        if (accountDeleted) {
            sendAccountsChangedBroadcast();
        }
    }

这段代码没有做任何事情。我觉得正在抛出异常,这是在较低层处理的。

How can I delete google accounts from "accounts and sync"? I'm trying to call this line my app:

AccountManagerService.getSingleton().onServiceChanged(null,true);

whereas onServiceChanged() method is defined in AccountManagerService.java.

public void onServiceChanged(AuthenticatorDescription desc, boolean removed) {
    boolean accountDeleted = false;
    SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    Cursor cursor = db.query(TABLE_ACCOUNTS,
            new String[]{ACCOUNTS_ID, ACCOUNTS_TYPE, ACCOUNTS_NAME},
            ACCOUNTS_TYPE + "=?", new String[]{desc.type}, null, null, null);
    try {
        while (cursor.moveToNext()) {
            final long accountId = cursor.getLong(0);
            final String accountType = cursor.getString(1);
            final String accountName = cursor.getString(2);
            Log.d(TAG, "deleting account " + accountName + " because type "
                    + accountType + " no longer has a registered authenticator");
            db.delete(TABLE_ACCOUNTS, ACCOUNTS_ID + "=" + accountId, null);
            accountDeleted = true;
        }
    } finally {
        cursor.close();
        if (accountDeleted) {
            sendAccountsChangedBroadcast();
        }
    }

This piece of code is not doing anything. I feel exception is being thrown which is handled at lower layer.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文