Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 有多个应用程序管理一个内容提供商-安装\u失败\u冲突\u提供商_Android_Android Contentprovider - Fatal编程技术网

Android 有多个应用程序管理一个内容提供商-安装\u失败\u冲突\u提供商

Android 有多个应用程序管理一个内容提供商-安装\u失败\u冲突\u提供商,android,android-contentprovider,Android,Android Contentprovider,我需要有几个应用程序使用同一个内容提供商。用户安装的第一个应用程序创建提供程序并添加UUID,每安装一个应用程序,检查此提供程序是否已存在并使用该UUID,或者,如果之前没有安装其他应用程序,则用户使用UUID创建内容提供程序,供其他应用程序使用 我如何做到这一点,让多个应用程序管理同一个内容提供商,而不会因为拥有相同的权限而产生以下错误 INSTALL_FAILED_CONFLICTING_PROVIDER 我能否以某种方式更改提供商权限并让其访问同一个内容提供商?如果我更改权限并使用相同的

我需要有几个应用程序使用同一个内容提供商。用户安装的第一个应用程序创建提供程序并添加UUID,每安装一个应用程序,检查此提供程序是否已存在并使用该UUID,或者,如果之前没有安装其他应用程序,则用户使用UUID创建内容提供程序,供其他应用程序使用

我如何做到这一点,让多个应用程序管理同一个内容提供商,而不会因为拥有相同的权限而产生以下错误

INSTALL_FAILED_CONFLICTING_PROVIDER
我能否以某种方式更改提供商权限并让其访问同一个内容提供商?如果我更改权限并使用相同的url,它会告诉我它无效


谢谢

这可能不是最好的方法。提供者ID在系统范围内是唯一的,在给定的时间内不能有多个提供者ID。但是,如果你想坚持下去,你可以阅读更多关于它的信息,然后继续

你需要它才能从应用程序访问数据?最好使用意图或其他策略作为文件或在线数据库


您可以查看一下以帮助解决您的问题。

我已经找到了一种不同的方法来解决这个问题,通过从Android Id创建一个唯一的标识符,并使用在手机未出厂重置时相同的Android Id,我可以拥有一个唯一的、不可更改的Id,因此任何应用程序都可以加载这个Id

这是我使用的代码:

/**
     * 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();
    }

@Mauker所有应用程序都必须具有设备的唯一id,因此,无论安装了什么应用程序,都必须首先声明该id。我不需要多个提供商,我只使用一个,我需要的是多个能够创建和读取单个提供商的应用程序。恐怕您必须重新考虑您的设计。