【问题标题】:How to synchronize data between an account and a web server in android?如何在android中的帐户和Web服务器之间同步数据?
【发布时间】:2014-07-08 09:39:49
【问题描述】:

如何在android中实现账号和web服务器之间的数据同步?

我创建了一个项目,我正在尝试创建自己的帐户,并且我想通过该帐户在特定时间间隔后获取服务器数据。到目前为止,我已经google了,我找到了这个useful link

这告诉我很多。但我无法清楚地知道为我的项目做什么。我当然会感谢任何帮助或建议。以下是我为创建帐户所做的工作:-

    public void onClick(View arg0) {
//              startActivity(new Intent(Settings.ACTION_ADD_ACCOUNT));
                str1 = ed1.getText().toString();
                str2 = ed2.getText().toString();
                if ((str1.matches(""))||(!str1.contains("@myapp.com"))) {
                    Toast.makeText(MainActivity.this, "Invalid type of User email id!", Toast.LENGTH_SHORT).show();
                    return;
                }
                if (str2.matches("")) {
                    Toast.makeText(MainActivity.this, "You did not enter a password", Toast.LENGTH_SHORT).show();
                    return;
                }
                Account account = new Account(str1, "com.example.accountMy");
                String password = str2;
                AccountManager accountManager = AccountManager.get(context);
                boolean success = accountManager.addAccountExplicitly(account, password, null);
                if(success){
                    Toast.makeText(MainActivity.this, "Myapp Account Created!", Toast.LENGTH_LONG).show();
                }else{
                    Toast.makeText(MainActivity.this, "Account is not Created!", Toast.LENGTH_LONG).show();
                }
            }});

我已经使用 Customauthenticator 和 AcountauthenticatorService 类来验证我的帐户。请指教。

【问题讨论】:

    标签: android sql-server-2005 synchronization account android-syncadapter


    【解决方案1】:

    要与服务器同步,您需要扩展 AbstractThreadedSyncAdapter 类并覆盖 onPerformSync 方法。通过这种方法,您应该从服务器获取数据并插入到您的内容提供程序中。完整代码请查看this link

    【讨论】:

    • 谢谢比尔盖茨。我正在查看您建议的链接,如果我通过了,肯定会正确标记它。如果可以的话,请帮我提供更多细节。再次感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-01
    • 1970-01-01
    • 2020-03-08
    • 2012-09-26
    • 2014-05-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多