1

I need to have several apps using a same content provider. The first app that the user install creates the provider and adds a UUID, every other app, when installed, check if this provider already exists and use that UUID, or, if there is no other app installed before, they create the content provider with the UUID for the others app to use.

How can I achieve this, having several apps managing the same content provider without the following error generating problems for having the same authority.

INSTALL_FAILED_CONFLICTING_PROVIDER

Can I, somehow, change the provider authority and have it access the same content provider? If I change the authority and use the same url it tells me it isn't valid.

Thanks!

Javier Bullrich
  • 389
  • 1
  • 5
  • 22
  • @Mauker all the apps must have a unique id for the device, so, whatever app is installed first declare that id. I don't need multiple providers, I only use one, what I need is multiple apps having the ability to create and read that single provider. – Javier Bullrich Mar 07 '17 at 19:04
  • 1
    I'm afraid you have to rethink your design. – Okas Mar 07 '17 at 19:11

2 Answers2

1

That's probably not the best way of doing it. Provider IDs are unique system wide and you really can't have more than one at a given time. But if you want to stick with it, you can read more about it here and here.

You'll need that to access data from an app? It's best to do that using Intents or some other strategy as files, or an online database.

You could take a look at Realm to help solve your issue.

Mauker
  • 11,237
  • 7
  • 58
  • 76
0

I have managed to get a different approach to this, by creating an Unique identifier from this post and using the Android Id that will be the same while the phone isn't factory reseted, I can have an unique, not changeable ID, so any app just load this ID.

This is the code I used:

/**
     * Return pseudo unique ID
     * @return ID
     */
    public static String getUniquePsuedoID(Context context) {
        // If all else fails, if the user does have lower than API 9 (lower
        // than Gingerbread), has reset their device or 'Secure.ANDROID_ID'
        // returns 'null', then simply the ID returned will be solely based
        // off their Android device information. This is where the collisions
        // can happen.
        // Thanks http://www.pocketmagic.net/?p=1662!
        // Try not to use DISPLAY, HOST or ID - these items could change.
        // If there are collisions, there will be overlapping data
        String android_id = Settings.Secure.getString(context.getContentResolver(),
                Settings.Secure.ANDROID_ID);
        String m_szDevIDShort = "35" + (Build.BOARD.length() % 10) + android_id + (Build.BRAND.length() % 10) + (Build.CPU_ABI.length() % 10) + (Build.DEVICE.length() % 10) + (Build.MANUFACTURER.length() % 10) + (Build.MODEL.length() % 10) + (Build.PRODUCT.length() % 10);

        // Thanks to @Roman SL!
        // https://stackoverflow.com/a/4789483/950427
        // Only devices with API >= 9 have android.os.Build.SERIAL
        // http://developer.android.com/reference/android/os/Build.html#SERIAL
        // If a user upgrades software or roots their device, there will be a duplicate entry
        String serial = null;
        try {
            serial = android.os.Build.class.getField("SERIAL").get(null).toString();

            // Go ahead and return the serial for api => 9
            return new UUID(m_szDevIDShort.hashCode(), serial.hashCode()).toString();
        } catch (Exception exception) {
            // String needs to be initialized
            serial = "serial"; // some value
        }

        // Thanks @Joe!
        // https://stackoverflow.com/a/2853253/950427
        // Finally, combine the values we have found by using the UUID class to create a unique identifier
        return new UUID(m_szDevIDShort.hashCode(), serial.hashCode()).toString();
    }
Community
  • 1
  • 1
Javier Bullrich
  • 389
  • 1
  • 5
  • 22