I'm using an account manager account in a service (which extends FirebaseInstanceIdService). If theres no valid account then I add the account using accountManager.addAccount.
That takes as a parameter activity (which is used for starting the account log-in activity). However as I'm calling addAccount from a service I don't have a current activity to place there. How do I call addAccount from a service and get it to display the account login where needed?
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
private static final String TAG = "MyFirebaseIIDService";
@Override
public void onTokenRefresh() {
AccountManager accountManager = (AccountManager) getApplicationContext().getSystemService(ACCOUNT_SERVICE);
Account account[] = accountManager.getAccountsByType(ACCOUNT_TYPE);
if(account.length==0) {
Activity activity=???????//What can I set here
accountManager.addAccount(ACCOUNT_TYPE, AccountGeneral.AUTHTOKEN_TYPE_FULL_ACCESS, null,
null, activity, new AccountManagerCallback<Bundle>() {
public void run(AccountManagerFuture<Bundle> arg0) {
}
}, null);
return null;
}
//do stuff with ContentResolver using account
}
}
addAccount()
method requires Activity instance to call the default Authenticator Activity.Their is another method called
addAccountExplicitly()
in AccountManager class. Here is the documentation:Usage:
Create Account instance:
Initialise account metadata:
Call addAccountExplicitly() method:
This will be good to go. Good luck!