Skip to content

Instantly share code, notes, and snippets.

@jerluc
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jerluc/3805f42caa2a97167373 to your computer and use it in GitHub Desktop.
Save jerluc/3805f42caa2a97167373 to your computer and use it in GitHub Desktop.
Resolving a deeplink on Android using a plain URI and the URX SDK
package my.cool.app;
import android.content.Context;
import com.urx.android.AndroidClient;
import com.urx.android.resolve.AndroidResolver;
import com.urx.core.ClientConfig;
import com.urx.core.resolution.UriResolve;
public class Resolve {
static final ClientConfig config = new ClientConfig("INSERT-API-KEY-HERE");
static final AndroidClient client = new AndroidClient(config);
/**
* Given a "plain" URL (such as http://spotify.com/blah), attempts to deeplink the user into
* the corresponding page in the app, or falls back to the mobile website if they app is not yet
* installed.
* @param uri A "plain" URL such as http://spotify.com/blah
* @param appContext Your app's Context (typically just a reference to the current Activity)
*/
public void launchDeeplink(String uri, Context appContext) {
// Small tweak for using a URI directly
String cleanedUri = uri.replaceAll("//", "/");
// Will open the app if it is installed, otherwise will default to the mobile website
client.resolve(new UriResolve(cleanedUri), AndroidResolver.installedApps(appContext));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment