Search in sources :

Example 1 with DynamicLink

use of com.google.firebase.dynamiclinks.DynamicLink in project snippets-android by firebase.

the class DynamicLinksUtil method generateContentLink.

// [START ddl_generate_content_link]
public static Uri generateContentLink() {
    Uri baseUrl = Uri.parse("https://your-custom-name.page.link");
    String domain = "https://your-app.page.link";
    DynamicLink link = FirebaseDynamicLinks.getInstance().createDynamicLink().setLink(baseUrl).setDomainUriPrefix(domain).setIosParameters(new DynamicLink.IosParameters.Builder("com.your.bundleid").build()).setAndroidParameters(new DynamicLink.AndroidParameters.Builder("com.your.packageName").build()).buildDynamicLink();
    return link.getUri();
}
Also used : DynamicLink(com.google.firebase.dynamiclinks.DynamicLink) Uri(android.net.Uri)

Example 2 with DynamicLink

use of com.google.firebase.dynamiclinks.DynamicLink in project quickstart-android by firebase.

the class MainActivity method buildDeepLink.

// [END on_create]
/**
 * Build a Firebase Dynamic Link.
 * https://firebase.google.com/docs/dynamic-links/android/create#create-a-dynamic-link-from-parameters
 *
 * @param deepLink the deep link your app will open. This link must be a valid URL and use the
 *                 HTTP or HTTPS scheme.
 * @param minVersion the {@code versionCode} of the minimum version of your app that can open
 *                   the deep link. If the installed app is an older version, the user is taken
 *                   to the Play store to upgrade the app. Pass 0 if you do not
 *                   require a minimum version.
 * @return a {@link Uri} representing a properly formed deep link.
 */
@VisibleForTesting
public Uri buildDeepLink(@NonNull Uri deepLink, int minVersion) {
    String uriPrefix = getString(R.string.dynamic_links_uri_prefix);
    // Set dynamic link parameters:
    // * URI prefix (required)
    // * Android Parameters (required)
    // * Deep link
    // [START build_dynamic_link]
    DynamicLink.Builder builder = FirebaseDynamicLinks.getInstance().createDynamicLink().setDomainUriPrefix(uriPrefix).setAndroidParameters(new DynamicLink.AndroidParameters.Builder().setMinimumVersion(minVersion).build()).setLink(deepLink);
    // Build the dynamic link
    DynamicLink link = builder.buildDynamicLink();
    // Return the dynamic link as a URI
    return link.getUri();
}
Also used : DynamicLink(com.google.firebase.dynamiclinks.DynamicLink) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 3 with DynamicLink

use of com.google.firebase.dynamiclinks.DynamicLink in project firebase-android-sdk by firebase.

the class DynamicLinksTest method buildDynamicLink_UriContainsCorrectComponents.

@Test
public void buildDynamicLink_UriContainsCorrectComponents() throws Exception {
    FirebaseDynamicLinks dl = FirebaseDynamicLinks.getInstance();
    Uri uri = Uri.parse("http://www.example.com");
    DynamicLink link = dl.createDynamicLink().setLink(uri).setDomainUriPrefix("http://example.page.link").setAndroidParameters(new DynamicLink.AndroidParameters.Builder().build()).buildDynamicLink();
    Uri actual = link.getUri();
    String[] query = actual.getQuery().split("&");
    assertThat(actual.getScheme()).isEqualTo("http");
    assertThat(actual.getHost()).isEqualTo("example.page.link");
    assertThat(query).asList().containsAtLeast("apn=com.google.firebase.testing", "link=http://www.example.com");
}
Also used : DynamicLink(com.google.firebase.dynamiclinks.DynamicLink) Uri(android.net.Uri) FirebaseDynamicLinks(com.google.firebase.dynamiclinks.FirebaseDynamicLinks) Test(org.junit.Test)

Example 4 with DynamicLink

use of com.google.firebase.dynamiclinks.DynamicLink in project snippets-android by firebase.

the class MainActivity method createDynamicLink_Basic.

public void createDynamicLink_Basic() {
    // [START create_link_basic]
    DynamicLink dynamicLink = FirebaseDynamicLinks.getInstance().createDynamicLink().setLink(Uri.parse("https://www.example.com/")).setDomainUriPrefix("https://example.page.link").setAndroidParameters(new DynamicLink.AndroidParameters.Builder().build()).setIosParameters(new DynamicLink.IosParameters.Builder("com.example.ios").build()).buildDynamicLink();
    Uri dynamicLinkUri = dynamicLink.getUri();
// [END create_link_basic]
}
Also used : ShortDynamicLink(com.google.firebase.dynamiclinks.ShortDynamicLink) DynamicLink(com.google.firebase.dynamiclinks.DynamicLink) Uri(android.net.Uri)

Aggregations

DynamicLink (com.google.firebase.dynamiclinks.DynamicLink)4 Uri (android.net.Uri)3 VisibleForTesting (androidx.annotation.VisibleForTesting)1 FirebaseDynamicLinks (com.google.firebase.dynamiclinks.FirebaseDynamicLinks)1 ShortDynamicLink (com.google.firebase.dynamiclinks.ShortDynamicLink)1 Test (org.junit.Test)1