/** * Navigates to an {@link bolts.AppLink}. * * @param context the Context from which the navigation should be performed. * @param appLink the AppLink being navigated to. * @return the {@link bolts.AppLinkNavigation.NavigationResult} performed by navigating. */ public static NavigationResult navigate(Context context, AppLink appLink) { return new AppLinkNavigation(appLink, null, null).navigate(context); }
/** * Navigates to an {@link bolts.AppLink} for the given destination using the default * App Link resolution strategy. * * @param context the Context from which the navigation should be performed. * @param destination the destination URL for the App Link. * @return the {@link bolts.AppLinkNavigation.NavigationResult} performed by navigating. */ public static Task<NavigationResult> navigateInBackground(Context context, Uri destination) { return navigateInBackground(context, destination, getResolver(context)); }
/** * Creates a bundle containing the final, constructed App Link data to be used in navigation. */ private Bundle buildAppLinkDataForNavigation() { Bundle data = new Bundle(); data.putAll(getAppLinkData()); data.putString(AppLinks.KEY_NAME_TARGET, getAppLink().getSourceUrl().toString()); data.putString(KEY_NAME_VERSION, VERSION); data.putString(KEY_NAME_USER_AGENT, "Bolts Android " + Bolts.VERSION); data.putBundle(AppLinks.KEY_NAME_EXTRAS, getExtras()); return data; }
PackageManager pm = context.getPackageManager(); Bundle finalAppLinkData = buildAppLinkDataForNavigation(); for (AppLink.Target target : getAppLink().getTargets()) { Intent targetIntent = new Intent(Intent.ACTION_VIEW); if (target.getUrl() != null) { Uri webUrl = getAppLink().getWebUrl(); if (webUrl != null) { JSONObject appLinkDataJson; try { appLinkDataJson = getJSONForBundle(finalAppLinkData); } catch (JSONException e) { throw new RuntimeException(e);
return getJSONForBundle((Bundle) value); } else if (value instanceof CharSequence) { return value.toString(); JSONArray array = new JSONArray(); for (Object listValue : (List<?>) value) { array.put(getJSONValue(listValue)); SparseArray<?> sparseValue = (SparseArray<?>) value; for (int i = 0; i < sparseValue.size(); i++) { array.put(sparseValue.keyAt(i), getJSONValue(sparseValue.valueAt(i))); JSONArray array = new JSONArray(); for (boolean arrValue : (boolean[]) value) { array.put(getJSONValue(arrValue)); JSONArray array = new JSONArray(); for (char arrValue : (char[]) value) { array.put(getJSONValue(arrValue)); JSONArray array = new JSONArray(); for (CharSequence arrValue : (CharSequence[]) value) { array.put(getJSONValue(arrValue)); JSONArray array = new JSONArray(); for (double arrValue : (double[]) value) { array.put(getJSONValue(arrValue)); JSONArray array = new JSONArray();
private static AppLinkResolver getResolver(Context context) { if (getDefaultResolver() != null) { return getDefaultResolver(); } return new WebViewAppLinkResolver(context); }
@Override public NavigationResult then(Task<AppLink> task) throws Exception { return navigate(context, task.getResult()); } }, Task.UI_THREAD_EXECUTOR);
/** * Gets a JSONObject equivalent to the input bundle for use when falling back to a web navigation. */ private JSONObject getJSONForBundle(Bundle bundle) throws JSONException { JSONObject root = new JSONObject(); for (String key : bundle.keySet()) { root.put(key, getJSONValue(bundle.get(key))); } return root; }
/** * Navigates to an {@link bolts.AppLink} for the given destination using the default * App Link resolution strategy. * * @param context the Context from which the navigation should be performed. * @param destination the destination URL for the App Link. * @return the {@link bolts.AppLinkNavigation.NavigationResult} performed by navigating. */ public static Task<NavigationResult> navigateInBackground(Context context, URL destination) { return navigateInBackground(context, destination, getResolver(context)); }
/** * Navigates to an {@link bolts.AppLink} for the given destination using the default * App Link resolution strategy. * * @param context the Context from which the navigation should be performed. * @param destinationUrl the destination URL for the App Link. * @return the {@link bolts.AppLinkNavigation.NavigationResult} performed by navigating. */ public static Task<NavigationResult> navigateInBackground(Context context, String destinationUrl) { return navigateInBackground(context, destinationUrl, getResolver(context)); } }