【问题标题】:Have several apps managing one content provider - INSTALL_FAILED_CONFLICTING_PROVIDER让多个应用管理一个内容提供者 - INSTALL_FAILED_CONFLICTING_PROVIDER
【发布时间】:2017-03-07 18:44:02
【问题描述】:

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

如何实现这一点,让多个应用管理同一个内容提供者,而不会出现以下错误,因为拥有相同的权限会产生问题。

INSTALL_FAILED_CONFLICTING_PROVIDER

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

谢谢!

【问题讨论】:

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

标签: android android-contentprovider


【解决方案1】:

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

您需要它来访问应用程序中的数据吗?最好使用 Intents 或其他策略作为文件或在线数据库来做到这一点。

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

【讨论】:

    【解决方案2】:

    我设法获得了一种不同的方法,通过从this post 创建一个唯一标识符并使​​用在手机未恢复出厂设置时相同的 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();
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多