segmentio / analytics-android

The hassle-free way to add analytics to your Android app.

Home Page:https://segment.com/docs/sources/mobile/android/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow using custom SharedPreferences, e.g. EncryptedSharedPreferences

alexeyvasilyev opened this issue · comments

Right now it is impossible to use custom SharedPrefences file, e.g. EncryptedSharedPreferences. We need an ability to specify custom SharedPreferences via Analytics.Builder.

  String masterKeyAlias = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC);

  SharedPreferences sharedPreferences = EncryptedSharedPreferences.create(
      "secret_shared_prefs",
      masterKeyAlias,
      context,
      EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
      EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
  );

  Analytics analytics = new Analytics.Builder(context, YOUR_WRITE_KEY)
    .trackApplicationLifecycleEvents()
    .recordScreenViews()
    .sharedPreferences(sharedPreferences)
    .build();

Found solution to use Builder crypto(Crypto crypto)