2013년 2월 26일 화요일

get shared preference from other app

App 1:




Context otherAppsContext = null;
try {
otherAppsContext = createPackageContext(
"com.example.sharedpreferencehosttest",
Context.CONTEXT_IGNORE_SECURITY);
} catch (NameNotFoundException e) {
}

SharedPreferences.Editor editor = otherAppsContext
.getSharedPreferences(
"PREFS_FILE",
Context.CONTEXT_IGNORE_SECURITY).edit();
editor.putString("sharedpreferencehosttest", "sogi");
editor.commit();



App 2:




Context otherAppsContext = null;
try {
otherAppsContext = createPackageContext(
"com.example.sharedpreferencehosttest",
Context.CONTEXT_IGNORE_SECURITY);
} catch (NameNotFoundException e) {
}

SharedPreferences sharedPreferences = otherAppsContext
.getSharedPreferences("PREFS_FILE", Context.CONTEXT_IGNORE_SECURITY);

Toast.makeText(
this,
sharedPreferences.getString("sharedpreferencehosttest",
"can not get value"), Toast.LENGTH_LONG).show();



댓글 없음:

댓글 쓰기