不同App共享SharedPreferences(跨activity, application訪問SharedPreferences)

寫SharedPreferences的時候設置屬性爲Context.MODE_WORLD_READABLE:

SharedPreferences sharedPreferences = getSharedPreferences(shareName, MODE_WORLD_READABLE);

訪問的時候:

Context otherContext = null;
try { 
    otherContext = createPackageContext("com.android.settings", Context.CONTEXT_IGNORE_SECURITY);
} catch (NameNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
SharedPreferences sharedPreferences = otherContext.getSharedPreferences(shareName, MODE_WORLD_READABLE);


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章