Hello everyone, how are you doing?
I have a question regarding the use of the Preferences plugin in Ionic > [Preferences Capacitor Plugin API | Ionic Documentation](https://Plugin Capacitor Preferences) , which employs UserDefaults on iOS and SharedPreferences on Android. My concern revolves around the interoperability between native code (Android or iOS) and Ionic, particularly when it comes to saving data natively.
For instance, when using SharedPreferences on Android, I would like to confirm if it’s possible to retrieve this data directly in Ionic. The logic is that the Ionic Preferences plugin utilizes Android’s SharedPreferences, so theoretically, accessing the natively stored data should be feasible.
Exemple native code. (android)
import android.content.Context;
import android.content.SharedPreferences;
public class SharedPreferencesManager {
private static final String PREFS_NAME = "MyPrefs";
public static void saveData(Context context, String key, String value) {
SharedPreferences.Editor editor = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE).edit();
editor.putString(key, value);
editor.apply();
}
public static String getData(Context context, String key) {
SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
return prefs.getString(key, null);
}
}