I was just guessing how to access the DefaultSharedPreferences (set in a PreferenceActivity) from an application in a BroadcastReceiver, knowing that onReceive method comes with Context and Intent?
Best regards,
I was just guessing how to access the DefaultSharedPreferences (set in a PreferenceActivity) from an application in a BroadcastReceiver, knowing that onReceive method comes with Context and Intent?
Best regards,
Looking at the source of it, we can see getDefaultSharedPreferences actually uses getSharedPreferences. So we can use getSharedPreferences the same we getDefaultSharedPreferences uses it.
In this specific case (onReceive of a BroadcastReceiver) :
SharedPreferences settings = context.getSharedPreferences(context.getPackageName() + "_preferences", Context.MODE_PRIVATE);
In the BroadcastReceiver:
PreferenceManager.getDefaultSharedPreferences(context)