`
runfeel
  • 浏览: 907711 次
文章分类
社区版块
存档分类
最新评论

不同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);


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics