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


你可能感兴趣的:(不同App共享SharedPreferences(跨activity, application访问SharedPreferences))