2012-03-23 42 views
0

我需要訪問其他應用程序的sharedPreference的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 

我不知道它有什麼問題,誰可以幫助我,謝謝。

+0

你找到一個解決方案? – erdomester 2012-10-27 06:57:11

回答

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", ""); 
+0

我可以得到值,沒關係,但不能更改值,拋出異常。 – 2012-03-23 06:31:56

0

TRY THIS WAY ::

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") 
+0

年,我也喜歡U, – 2012-03-23 06:50:35

+0

mContext = this.createPackageContext(packName,Context.CONTEXT_IGNORE_SECURITY); SharedPreferences spf2 = mContext.getSharedPreferences(「public」,MODE_WORLD_WRITEABLE | MODE_WORLD_READABLE); \t \t Editor editor = spf2.edit(); editor.putBoolean(「preview」,true); \t \t editor.putInt(「overlay_size」,100); \t \t editor.commit(); – 2012-03-23 06:51:22

相關問題