Android Open Source - Bolts-Android App Links






From Project

Back to project page Bolts-Android.

License

The source code is released under:

BSD License For Bolts software Copyright (c) 2013, Facebook, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that t...

If you think the Android project Bolts-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 *  Copyright (c) 2014, Facebook, Inc.//w  ww .j ava 2 s  .  c o  m
 *  All rights reserved.
 *
 *  This source code is licensed under the BSD-style license found in the
 *  LICENSE file in the root directory of this source tree. An additional grant
 *  of patent rights can be found in the PATENTS file in the same directory.
 *
 */
package bolts;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

/**
 * Provides a set of utility methods for working with incoming Intents that may contain App Link
 * data.
 */
public final class AppLinks {

  static final String KEY_NAME_APPLINK_DATA = "al_applink_data";
  static final String KEY_NAME_EXTRAS = "extras";
  static final String KEY_NAME_TARGET = "target_url";

  /**
   * Gets the App Link data for an intent, if there is any.
   * This is the authorized function to check if an intent is AppLink. If null is returned it is not.
   *
   * @param intent the incoming intent.
   * @return a bundle containing the App Link data for the intent, or {@code null} if none
   * is specified.
   */
  public static Bundle getAppLinkData(Intent intent) {
    return intent.getBundleExtra(KEY_NAME_APPLINK_DATA);
  }

  /**
   * Gets the App Link extras for an intent, if there is any.
   *
   * @param intent the incoming intent.
   * @return a bundle containing the App Link extras for the intent, or {@code null} if none is
   * specified.
   */
  public static Bundle getAppLinkExtras(Intent intent) {
    Bundle appLinkData = getAppLinkData(intent);
    if (appLinkData == null) {
      return null;
    }
    return appLinkData.getBundle(KEY_NAME_EXTRAS);
  }

  /**
   * Gets the target URL for an intent, regardless of whether the intent is from an App Link. If the
   * intent is from an App Link, this will be the App Link target. Otherwise, it will be the data
   * Uri from the intent itself.
   *
   * @param intent the incoming intent.
   * @return the target URL for the intent.
   */
  public static Uri getTargetUrl(Intent intent) {
    Bundle appLinkData = getAppLinkData(intent);
    if (appLinkData != null) {
      String targetString = appLinkData.getString(KEY_NAME_TARGET);
      if (targetString != null) {
        return Uri.parse(targetString);
      }
    }
    return intent.getData();
  }

  /**
   * Gets the target URL for an intent. If the intent is from an App Link, this will be the App Link target.
   * Otherwise, it return null; For app link intent, this function will broadcast APP_LINK_NAVIGATE_IN_EVENT_NAME event.
   *
   * @param context the context this function is called within.
   * @param intent the incoming intent.
   * @return the target URL for the intent if applink intent; null otherwise.
   */
  public static Uri getTargetUrlFromInboundIntent(Context context, Intent intent) {
    Bundle appLinkData = getAppLinkData(intent);
    if (appLinkData != null) {
      String targetString = appLinkData.getString(KEY_NAME_TARGET);
      if (targetString != null) {
        MeasurementEvent.sendBroadcastEvent(context, MeasurementEvent.APP_LINK_NAVIGATE_IN_EVENT_NAME, intent, null);
        return Uri.parse(targetString);
      }
    }
    return null;
  }
}




Java Source Code List

bolts.AggregateException.java
bolts.AndroidExecutorsTest.java
bolts.AndroidExecutors.java
bolts.AppLinkNavigation.java
bolts.AppLinkResolver.java
bolts.AppLinkTest.java
bolts.AppLink.java
bolts.AppLinks.java
bolts.BoltsExecutors.java
bolts.Bolts.java
bolts.Capture.java
bolts.Continuation.java
bolts.MeasurementEvent.java
bolts.TaskTest.java
bolts.Task.java
bolts.WebViewAppLinkResolver.java
bolts.utils.BoltsActivity2.java
bolts.utils.BoltsActivity.java