不同包之间的 SharedPreferences 管理

SharedPreferences managing between different packages

我正在使用软件包 com.example1 开发一个应用程序,我正在开发另一个模块以用作带有软件包 com.example2.

的库

在我的模块 (com.example2) 上,我正在使用这个静态函数:

    public static void saveLastDownload(Activity mActivity, long numberLong) {
        SharedPreferences sharedPref = mActivity.getPreferences(Context.MODE_APPEND);
        SharedPreferences.Editor editor = sharedPref.edit();
        editor.putLong(dataLastDownloadKey, numberLong);
        boolean commit = editor.commit();
    }

    public static long readLastDownload(Activity mActivity, long defaultValue) {
        SharedPreferences sharedPref = mActivity.getPreferences(Context.MODE_PRIVATE);
        return sharedPref.getLong(dataLastDownloadKey, defaultValue);
    }

我正在尝试从 com.example1 saveDownloadreadLastDownload,但我对这些共享偏好没有任何价值。我如何以现代方式读取此值(没有任何安全漏洞,尽管我对将其设为私有不感兴趣)。

我该怎么做?

非常感谢您。

如果您想使用首选项执行此操作:MODE_WORLD_READABLE

Creating world-writable files is very dangerous, and likely to cause security holes in applications. It is strongly discouraged; instead, applications should use more formal mechanism for interactions such as ContentProvider, BroadcastReceiver, and Service.