关于另一个访问SharedPreference的应用程序

时间:2012-03-23 06:24:05

标签: android

我需要访问另一个应用程序的sharedPreference,SharedPreference必须设置

"MODE_WORLD_WRITEABLE|MODE_WORLD_READABLE",并向您展示Logcat。

03-23 13:54:45.038: E/ApplicationContext(10895): Couldn't rename file /data/data/com.mzw.gamehelper/shared_prefs/public.xml to backup file /data/data/com.mzw.gamehelper/shared_prefs/public.xml.bak

我不知道它有什么问题,谁可以帮助我,谢谢你。

2 个答案:

答案 0 :(得分:0)

尝试此代码插入值

 private SharedPreferences myPrefs;
    myPrefs = Actionactivity.this.getSharedPreferences("myPrefs", MODE_WORLD_WRITEABLE);
    SharedPreferences.Editor prefsEditor = myPrefs.edit();
    prefsEditor.putString("Mobile_no", getText_no.getText().toString().trim());
    prefsEditor.commit();

并尝试此代码获取值

myPrefs = this.getSharedPreferences("myPrefs", MODE_WORLD_READABLE);
myPrefs.getString("Mobile_no", "");

答案 1 :(得分:0)

尝试这种方式::

Context otherAppsContext = null;
private SharedPreferences sharedPreferences;
public static final String PREFS_READ = "PREFS_READ";
public static final String KEY_READ = "KEY_READ";
try {
  //com.dfdf.fdfdf.android.sharedpreferences OTHER APPLICTION PACKAGE NAME
       otherAppsContext = createPackageContext("com.dfdf.fdfdf.android.sharedpreferences", 0);
    } catch (NameNotFoundException e) {
    }
 sharedPreferences = otherAppsContext.getSharedPreferences(PREFS_READ, Context.MODE_WORLD_WRITEABLE);
 String strvalue=sharedPreferences.getString(KEY_READ, "WORLD READ EMPTY")