1

I'm developing one app, with the package com.example1 and I'm doing another module to use as a library with the package com.example2.

On my module (com.example2) I'm using this static functions:

    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);
    }

I'm trying to saveDownload and readLastDownload from com.example1 but I haven't got any value on these shared preferences. How can I read this value in a modern way (without any security holes, although I'm not interested in making it private).

How could I do it?

Thank you very much in advance.

4

1 回答 1

2

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

创建全局可写文件是非常危险的,并且可能会导致应用程序中的安全漏洞。强烈建议不要这样做;相反,应用程序应该使用更正式的交互机制,例如 ContentProviderBroadcastReceiverService

于 2015-12-11T19:49:27.673 回答