Autoadd account after application is installed

[亡魂溺海] 提交于 2019-12-25 18:43:08

问题


Is there any way to add automatically account just after installation my application (but it was not started yet).


回答1:


It is impossible to do anything "just after installation my application (but it was not started yet)". When the user launches your main activity, you can set up the account or whatever other sort of first-time event you want.




回答2:


Here is a peace of code which automatically activates account

    final AccountManager accountManager = AccountManager.get(this);
    String authority = getString(R.string.acc_authority);
    String accountType = getString(R.string.acc_name);
    String accountName = getString(R.string.app_name);

    Account[] existingAccs = accountManager.getAccountsByType(accountType);
    if (existingAccs.length > 0) {
        return;
    }

    Account account = new Account(accountName, accountType);
    if (accountManager.addAccountExplicitly(account, null, null)) {
        ContentResolver.setIsSyncable(account, authority, 1);
        ContentResolver.setSyncAutomatically(account, authority, true);
        ContentResolver.requestSync(account, authority, new Bundle());
        ContentResolver.addPeriodicSync(account, authority, new Bundle(), 60*10);
    }


来源:https://stackoverflow.com/questions/8758830/autoadd-account-after-application-is-installed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!