Last active
August 29, 2015 14:11
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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