Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot add new custom account from different app with same authenticator

I have two apps that both use a same custom account type. Those two apps are completely independent and just share the account. When one of them starts, it checks for existing custom accounts and if no account was found, shows the sign-in page.

So I have created my AccountAuthenticator as a library project and reference it in both apps. According to this tutorial:

Let’s say you copied your authenticator’s code to 2 of your apps, thus sharing its logic, and altering the sign-in pages design on each app to fit the app it belongs to. In that case, the first installed app’s authenticator will be called for both apps when an auth-token will be requested. If you uninstall the first app, the second app’s authenticator will be called from now on (since it’s the only one now).

When I run one of the apps (no matter which app) and call addAccount it shows the sign-in page well. Then, when I run the second app and call addAccount nothing happens and sign-in page is not shown. After uninstalling the first app, the second app works correctly and shows sign-in page. So what is the problem and how can I fix that?

The implementation of addAccount:

mAccountManager.addAccount(accountType, authTokenType, null, null, this, new AccountManagerCallback<Bundle>() {
            @Override
            public void run(AccountManagerFuture<Bundle> future) {
                try {
                    Bundle bnd = future.getResult();
                    showMessage("Account was created");
                } catch (Exception e) {
                    e.printStackTrace();
                    showMessage(e.getMessage());
                }
            }
        }, null);

Thanks in advance

like image 804
Misagh Emamverdi Avatar asked Sep 02 '15 11:09

Misagh Emamverdi


1 Answers

@Misagh Emamverdi Yeah .You missing that permission in your manifest .

android:sharedUserId

The name of a Linux user ID that will be shared with other applications. By default, Android assigns each application its own unique user ID. However, if this attribute is set to the same value for two or more applications, they will all share the same ID — provided that they are also signed by the same certificate.

Application with the same user ID can access each other's data and, if desired, run in the same process.

So android:sharedUserId is used to share the processes between two or more applications (Like Udinic Authenticator).

SYNTAX

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="string"
      android:sharedUserId="string"
      android:sharedUserLabel="string resource" 
      android:versionCode="integer"
      android:versionName="string"
      android:installLocation=["auto" | "internalOnly" | "preferExternal"] >
. . .

like image 183
IntelliJ Amiya Avatar answered Sep 30 '22 04:09

IntelliJ Amiya