diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 150952acd..8d3334961 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -95,6 +95,10 @@ android:label="@string/activity_name_feedback" android:configChanges="orientation|screenSize"> + + values = Countly.sharedInstance().remoteConfig().testingGetAllVariants(); + if (values == null) { + Countly.sharedInstance().L.w("No variants present"); + return; + } + Countly.sharedInstance().L.d("Get all variants: " + values); + + StringBuilder sb = new StringBuilder(); + sb.append("Stored Variant Values:\n"); + for (Map.Entry entry : values.entrySet()) { + String key = entry.getKey(); + String[] variants = entry.getValue(); + sb.append(key).append(": ").append(Arrays.toString(variants)).append("\n"); + } + + Toast t = Toast.makeText(getApplicationContext(), sb.toString(), Toast.LENGTH_LONG); + t.setGravity(Gravity.BOTTOM, 0, 0); + t.show(); + } + + public void onClickEnrollVariant(View v) { + Map values = Countly.sharedInstance().remoteConfig().testingGetAllVariants(); + if (values == null) { + Countly.sharedInstance().L.w("No variants present"); + return; + } + Countly.sharedInstance().L.d("Get all variants: [" + values.toString() + "]"); + + // Get the first key and variant + String key = null; + String variant = null; + for (Map.Entry entry : values.entrySet()) { + key = entry.getKey(); + variant = entry.getValue()[0]; // first variant + break; // Get only the first key-value pair + } + + Countly.sharedInstance().remoteConfig().testingEnrollIntoVariant(key, variant, new RCVariantCallback() { + @Override + public void callback(RequestResponse result, String error) { + if (result == RequestResponse.SUCCESS) { + Toast.makeText(getApplicationContext(), "Fetch finished", Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(getApplicationContext(), "Error: " + result, Toast.LENGTH_SHORT).show(); + } + } + }); + } + + @Override + public void onStart() { + super.onStart(); + Countly.sharedInstance().onStart(this); + } + + @Override + public void onStop() { + Countly.sharedInstance().onStop(); + super.onStop(); + } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + Countly.sharedInstance().onConfigurationChanged(newConfig); + } +} \ No newline at end of file diff --git a/app/src/main/java/ly/count/android/demo/MainActivity.java b/app/src/main/java/ly/count/android/demo/MainActivity.java index f50c5e24d..b08355fe4 100644 --- a/app/src/main/java/ly/count/android/demo/MainActivity.java +++ b/app/src/main/java/ly/count/android/demo/MainActivity.java @@ -130,6 +130,10 @@ public void onClickButtonRemoteConfig(View v) { startActivity(new Intent(this, ActivityExampleRemoteConfig.class)); } + public void onClickButtonTests(View v) { + startActivity(new Intent(this, ActivityExampleTests.class)); + } + public void onClickButtonDeviceId(View v) { startActivity(new Intent(this, ActivityExampleDeviceId.class)); } diff --git a/app/src/main/res/layout/activity_example_tests.xml b/app/src/main/res/layout/activity_example_tests.xml new file mode 100644 index 000000000..c91a77b26 --- /dev/null +++ b/app/src/main/res/layout/activity_example_tests.xml @@ -0,0 +1,43 @@ + + + + +