1
我正在開發一個應用程序,其中包含com.example1
,我正在做另一個模塊以用作包com.example2
的包。SharedPreferences在不同包裹之間管理
在我的模塊(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
試圖saveDownload
和readLastDownload
,但我還沒有得到這些共同的喜好任意值。我怎樣才能以現代的方式讀取這個值(沒有任何安全漏洞,儘管我不想讓它變得私密)。
我該怎麼辦?
非常感謝您提前。
Hello Elenasys。 我問的原因是因爲MODE_WORLD_READABLE從> = API 17已棄用,是不是有其他方式? –
Hola Rafael,我使用BroadcastReceiver在每個應用程序的偏好設置中發送數據並保存值。 – Jorgesys
所以我想這是唯一的選擇 –