在Android中使用下面的Code可以实现两个应用之间的SharedPreferences数据共享,但前提是要保证两个应用的android:sharedUserId要相同
Context context = null; try { context=createPackageContext("com.android.providers.downloads",Context.CONTEXT_IGNORE_SECURITY); } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } SharedPreferences mPrefs = context.getSharedPreferences("com.android.providers.downloads.save_preference", 0); boolean onlyWifi = mPrefs.getBoolean("download_only_wifi", false);
时间: 2024-11-04 22:23:36