Cannot add new custom account from different app with same authenticator
Asked Answered
C

3

12

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

Clearheaded answered 2/9, 2015 at 11:19 Comment(0)
C
3

I'm not sure this the correct answer, but I found that the problem is that the apps have different UIDs. So I use sharedUserId in both apps and the problem was solved:

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.test"
    android:sharedUserId="test.account"
    android:versionCode="100"
    android:versionName="1.0" >
Clearheaded answered 7/9, 2015 at 4:55 Comment(0)
J
5

@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"] >
. . .

Judgment answered 8/9, 2015 at 9:34 Comment(0)
C
3

I'm not sure this the correct answer, but I found that the problem is that the apps have different UIDs. So I use sharedUserId in both apps and the problem was solved:

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.test"
    android:sharedUserId="test.account"
    android:versionCode="100"
    android:versionName="1.0" >
Clearheaded answered 7/9, 2015 at 4:55 Comment(0)
P
3

Find the well written article Write your own Android Authenticator

enter image description here

Presumable answered 10/9, 2015 at 10:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.