开发者

Add account automatically

开发者 https://www.devze.com 2023-04-11 04:13 出处:网络
My application needs to synchronize some data from server. I added necessary classes (similarl开发者_运维问答y to SampleSyncAdapter) now I can add account via \"Settings/Sync and Accounts\".

My application needs to synchronize some data from server. I added necessary classes (similarl开发者_运维问答y to SampleSyncAdapter) now I can add account via "Settings/Sync and Accounts". But I want to have already added my account and working synchronization just after application is installed (I do not want user to do any manual changes in settings). How to do this?


A bit late but...

Account account = new Account("Title", "com.package.nom");
String password = "password";
AccountManager accountManager = AccountManager.get(context);
accountManager.addAccountExplicitly(account, password, null);


There is Android AtLeap library which contains helper classes to use Account Authenticator. Have a look at it https://github.com/blandware/android-atleap


Don't you have to add to the following code posted by Evan Elliott :

Account account = new Account("Title", "com.package.nom");
String password = "password";
AccountManager accountManager = AccountManager.get(context);
accountManager.addAccountExplicitly(account, password, null);

The following: ?

authenticator.xml

<?xml version="1.0" encoding="utf-8"?>

 <account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
    android:accountType="@string/account_type"
    android:icon="@drawable/icon_hdpi"
    android:smallIcon="@drawable/icon_hdpi"
    android:label="@string/authenticator_label"
 />

and permissions?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号