Localytics - application software key set

Can I programmatically set the application key for Localytics? From the integration guide ( https://support.localytics.com/Android_SDK_integration ) it seems that you should set it in the manifest file as metadata.

<meta-data android:name="LOCALYTICS_APP_KEY" android:value="APP KEY FROM STEP 2"/> 

From the following message, it also seems impossible to dynamically set Android metadata. How to add metadata dynamically (not in the manifest, but inside the code)?

I would like the dynamic application key to be based on Gradle buildType, so I can have a release application key and a debug application key.

+6
source share
3 answers

You can use manifest merging to support different application keys for your build types (e.g. debugging or release) or your products (e.g. free or paid).

To support various application keys for your build types:

  • Create src/debug/AndroidManifest.xml and src/release/AndroidManifest.xml .
  • Remove the metadata tag from src/main/AndroidManifest.xml .
  • Add the appropriate metadata tag to your assembly type manifest.

src/debug/AndroidManifest.xml

  <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.app" > <application> <meta-data android:name="LOCALYTICS_APP_KEY" android:value="DEBUG_APP_KEY" /> </application> </manifest> 

src/release/AndroidManifest.xml

  <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.app" > <application> <meta-data android:name="LOCALYTICS_APP_KEY" android:value="RELEASE_APP_KEY" /> </application> </manifest> 

For different application keys based on your product tastes, simply replace debug and release above with your product taste names.

+5
source

In Localitics.integrate there is an override that accepts the api key.

 Localytics.integrate(this, "API_KEY") 
+2
source

If you use autoIntegrate , use the following API, which takes the application context as the first argument.

 Localytics.autoIntegrate(this, "API_KEY"); 
0
source

Source: https://habr.com/ru/post/982759/


All Articles