Skip to content

Instantly share code, notes, and snippets.

View s0h4m's full-sized avatar

Soham Mondal s0h4m

View GitHub Profile

#Android best practices

@s0h4m
s0h4m / RemoteConfigManager.java
Created September 10, 2016 12:34
A simple way to determine if the current app version is in alpha or beta using Firebase Remote Config
import android.content.Context;
import android.support.annotation.NonNull;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.remoteconfig.FirebaseRemoteConfig;
public class RemoteConfigManager {
public static final String KEY_STABLE_VERSION = "stable_version";
import android.content.Context;
import android.support.annotation.NonNull;
import java.lang.ref.WeakReference;
import timber.log.Timber;
/**
* Our custom TimberTree that lets us output to a file via an {@link android.app.IntentService}
* like {@link TimberService}
@s0h4m
s0h4m / BasicId.java
Created June 8, 2016 07:12
Generates an anonymous analytics ID for non play-services powered devices
import android.content.Context;
/**
* A basic implementation of {@link Id} to be used in non play-services environments
*/
public class BasicId extends Id {
/**
* Get an analytics ID for non play-services powered devices, uses UUID to get the id
* @param context
* @return
@s0h4m
s0h4m / Id.java
Created June 8, 2016 07:11
Generates an anonymous id for analytics
import android.content.Context;
import java.util.UUID;
/**
* This generates an anonymous user id for analytics
*/
public abstract class Id {
abstract public String getId(final Context context);
@s0h4m
s0h4m / FirebaseId.java
Created June 8, 2016 07:10
Creates an anonymous id for analytics specifically for play-services devices. This can be derived from advertising-id or even the fem token.
import android.content.Context;
import android.support.annotation.Nullable;
import com.google.android.gms.ads.identifier.AdvertisingIdClient;
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.common.GooglePlayServicesRepairableException;
import com.google.firebase.iid.FirebaseInstanceId;
import java.io.IOException;
compile 'cc.soham:toggle:0.1'
@s0h4m
s0h4m / sample_toggle_config.json
Created March 4, 2016 09:46
A sample toggle (http://s0h4m.github.io/toggle/) config with two features, video and mixpanel, which are disabled/enabled using feature toggles
{"name": "myapp", "features":
[
{"name":"video", "default": "enabled", "rules":[
{"state": "disabled", "value":
{"apilevel_min": 21, "apilevel_max": 23, "device":[{"manufacturer":"xiaomi","model":"mi3"}, {"manufacturer":"samsung", "model":"s4"}]}
},
{"state": "disabled", "value": {"appversion_max": 13}}
]},
{"name":"crash_reporting", "rules":[
{"state": "disabled", "value":