com.google.firebase.dynamiclinks.FirebaseDynamicLinks Java Examples
The following examples show how to use
com.google.firebase.dynamiclinks.FirebaseDynamicLinks.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DynamicLinksTest.java From firebase-android-sdk with Apache License 2.0 | 6 votes |
@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"); }
Example #2
Source File: MainActivity.java From snippets-android with Apache License 2.0 | 6 votes |
public void createShortLink() { // [START create_short_link] Task<ShortDynamicLink> shortLinkTask = FirebaseDynamicLinks.getInstance().createDynamicLink() .setLink(Uri.parse("https://www.example.com/")) .setDomainUriPrefix("https://example.page.link") // Set parameters // ... .buildShortDynamicLink() .addOnCompleteListener(this, new OnCompleteListener<ShortDynamicLink>() { @Override public void onComplete(@NonNull Task<ShortDynamicLink> task) { if (task.isSuccessful()) { // Short link created Uri shortLink = task.getResult().getShortLink(); Uri flowchartLink = task.getResult().getPreviewLink(); } else { // Error // ... } } }); // [END create_short_link] }
Example #3
Source File: MainActivity.java From snippets-android with Apache License 2.0 | 6 votes |
public void shortenLongLink() { // [START shorten_long_link] Task<ShortDynamicLink> shortLinkTask = FirebaseDynamicLinks.getInstance().createDynamicLink() .setLongLink(Uri.parse("https://example.page.link/?link=https://www.example.com/&apn=com.example.android&ibn=com.example.ios")) .buildShortDynamicLink() .addOnCompleteListener(this, new OnCompleteListener<ShortDynamicLink>() { @Override public void onComplete(@NonNull Task<ShortDynamicLink> task) { if (task.isSuccessful()) { // Short link created Uri shortLink = task.getResult().getShortLink(); Uri flowchartLink = task.getResult().getPreviewLink(); } else { // Error // ... } } }); // [END shorten_long_link] }
Example #4
Source File: MainActivity.java From snippets-android with Apache License 2.0 | 6 votes |
public void getInvitation() { // [START ddl_get_invitation] FirebaseDynamicLinks.getInstance() .getDynamicLink(getIntent()) .addOnCompleteListener(new OnCompleteListener<PendingDynamicLinkData>() { @Override public void onComplete(@NonNull Task<PendingDynamicLinkData> task) { if (!task.isSuccessful()) { // Handle error // ... } FirebaseAppInvite invite = FirebaseAppInvite.getInvitation(task.getResult()); if (invite != null) { // Handle invite // ... } } }); // [END ddl_get_invitation] }
Example #5
Source File: MainActivity.java From quickstart-android with Apache License 2.0 | 6 votes |
/** * 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(); // [END build_dynamic_link] // Return the dynamic link as a URI return link.getUri(); }
Example #6
Source File: FirebaseDynamicLinkRegistrar.java From firebase-android-sdk with Apache License 2.0 | 5 votes |
@Override @Keep public List<Component<?>> getComponents() { Component<FirebaseDynamicLinks> firebaseDynamicLinks = Component.builder(FirebaseDynamicLinks.class) .add(Dependency.required(FirebaseApp.class)) .add(Dependency.optional(AnalyticsConnector.class)) .factory( container -> new FirebaseDynamicLinksImpl( container.get(FirebaseApp.class), container.get(AnalyticsConnector.class))) .build(); // no need for eager init for the Internal component. return Collections.singletonList(firebaseDynamicLinks); }
Example #7
Source File: DynamicLinksTest.java From firebase-android-sdk with Apache License 2.0 | 5 votes |
@Test public void getDynamicLink_NonLinkReturnsNull() throws Exception { FirebaseDynamicLinks dl = FirebaseDynamicLinks.getInstance(); Uri uri = Uri.parse("http://www.example.com"); Task<?> task = dl.getDynamicLink(uri); Object actual = Tasks2.waitForSuccess(task); assertThat(actual).isNull(); }
Example #8
Source File: DynamicLinksUtil.java From snippets-android with Apache License 2.0 | 5 votes |
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(); }
Example #9
Source File: ReferralActivity.java From snippets-android with Apache License 2.0 | 5 votes |
public void createLink() { // [START ddl_referral_create_link] FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); String uid = user.getUid(); String link = "https://mygame.example.com/?invitedby=" + uid; FirebaseDynamicLinks.getInstance().createDynamicLink() .setLink(Uri.parse(link)) .setDomainUriPrefix("https://example.page.link") .setAndroidParameters( new DynamicLink.AndroidParameters.Builder("com.example.android") .setMinimumVersion(125) .build()) .setIosParameters( new DynamicLink.IosParameters.Builder("com.example.ios") .setAppStoreId("123456789") .setMinimumVersion("1.0.1") .build()) .buildShortDynamicLink() .addOnSuccessListener(new OnSuccessListener<ShortDynamicLink>() { @Override public void onSuccess(ShortDynamicLink shortDynamicLink) { mInvitationUrl = shortDynamicLink.getShortLink(); // ... } }); // [END ddl_referral_create_link] }
Example #10
Source File: ReferralActivity.java From snippets-android with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // ... FirebaseDynamicLinks.getInstance() .getDynamicLink(getIntent()) .addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() { @Override public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) { // Get deep link from result (may be null if no link is found) Uri deepLink = null; if (pendingDynamicLinkData != null) { deepLink = pendingDynamicLinkData.getLink(); } // // If the user isn't signed in and the pending Dynamic Link is // an invitation, sign in the user anonymously, and record the // referrer's UID. // FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); if (user == null && deepLink != null && deepLink.getBooleanQueryParameter("invitedby", false)) { String referrerUid = deepLink.getQueryParameter("invitedby"); createAnonymousAccountWithReferrerInfo(referrerUid); } } }); }
Example #11
Source File: MainActivity.java From snippets-android with Apache License 2.0 | 5 votes |
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") // Open links with this app on Android .setAndroidParameters(new DynamicLink.AndroidParameters.Builder().build()) // Open links with com.example.ios on iOS .setIosParameters(new DynamicLink.IosParameters.Builder("com.example.ios").build()) .buildDynamicLink(); Uri dynamicLinkUri = dynamicLink.getUri(); // [END create_link_basic] }
Example #12
Source File: MainActivity.java From snippets-android with Apache License 2.0 | 5 votes |
public void createDynamicLink_Advanced() { // [START create_link_advanced] DynamicLink dynamicLink = FirebaseDynamicLinks.getInstance().createDynamicLink() .setLink(Uri.parse("https://www.example.com/")) .setDomainUriPrefix("https://example.page.link") .setAndroidParameters( new DynamicLink.AndroidParameters.Builder("com.example.android") .setMinimumVersion(125) .build()) .setIosParameters( new DynamicLink.IosParameters.Builder("com.example.ios") .setAppStoreId("123456789") .setMinimumVersion("1.0.1") .build()) .setGoogleAnalyticsParameters( new DynamicLink.GoogleAnalyticsParameters.Builder() .setSource("orkut") .setMedium("social") .setCampaign("example-promo") .build()) .setItunesConnectAnalyticsParameters( new DynamicLink.ItunesConnectAnalyticsParameters.Builder() .setProviderToken("123456") .setCampaignToken("example-promo") .build()) .setSocialMetaTagParameters( new DynamicLink.SocialMetaTagParameters.Builder() .setTitle("Example of a Dynamic Link") .setDescription("This link works whether the app is installed or not!") .build()) .buildDynamicLink(); // Or buildShortDynamicLink() // [END create_link_advanced] }
Example #13
Source File: MainActivity.java From snippets-android with Apache License 2.0 | 5 votes |
public void buildShortSuffix() { // [START ddl_short_suffix] Task<ShortDynamicLink> shortLinkTask = FirebaseDynamicLinks.getInstance().createDynamicLink() // ... .buildShortDynamicLink(ShortDynamicLink.Suffix.SHORT); // ... // [END ddl_short_suffix] }
Example #14
Source File: MainActivity.java From snippets-android with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { // [START_EXCLUDE] super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Invite button click listener findViewById(R.id.inviteButton).setOnClickListener(this); // [END_EXCLUDE] // Check for App Invite invitations and launch deep-link activity if possible. // Requires that an Activity is registered in AndroidManifest.xml to handle // deep-link URLs. FirebaseDynamicLinks.getInstance().getDynamicLink(getIntent()) .addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() { @Override public void onSuccess(PendingDynamicLinkData data) { if (data == null) { Log.d(TAG, "getInvitation: no data"); return; } // Get the deep link Uri deepLink = data.getLink(); // Extract invite FirebaseAppInvite invite = FirebaseAppInvite.getInvitation(data); if (invite != null) { String invitationId = invite.getInvitationId(); } // Handle the deep link // [START_EXCLUDE] Log.d(TAG, "deepLink:" + deepLink); if (deepLink != null) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setPackage(getPackageName()); intent.setData(deepLink); startActivity(intent); } // [END_EXCLUDE] } }) .addOnFailureListener(this, new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { Log.w(TAG, "getDynamicLink:onFailure", e); } }); }