Пример #1
0
  /**
   * Called upon user click. Attempts open mopubnativebrowser links in the device browser and all
   * other links in the MoPub in-app browser.
   */
  @VisibleForTesting
  void handleClick(final List<String> clickThroughTrackers, final String clickThroughUrl) {
    makeTrackingHttpRequest(clickThroughTrackers, getContext(), BaseEvent.Name.CLICK_REQUEST);

    if (clickThroughUrl == null) {
      return;
    }

    broadcastAction(ACTION_INTERSTITIAL_CLICK);

    if (Intents.isNativeBrowserScheme(clickThroughUrl)) {
      try {
        final Intent intent = Intents.intentForNativeBrowserScheme(clickThroughUrl);
        Intents.startActivity(getContext(), intent);
        return;
      } catch (UrlParseException e) {
        MoPubLog.d(e.getMessage());
      } catch (IntentNotResolvableException e) {
        MoPubLog.d("Could not handle intent for URI: " + clickThroughUrl + ". " + e.getMessage());
      }

      return;
    }

    Bundle bundle = new Bundle();
    bundle.putString(MoPubBrowser.DESTINATION_URL_KEY, clickThroughUrl);

    getBaseVideoViewControllerListener()
        .onStartActivityForResult(MoPubBrowser.class, MOPUB_BROWSER_REQUEST_CODE, bundle);
  }
 @Override
 protected void performAction(
     @NonNull final Context context,
     @NonNull final Uri uri,
     @NonNull final UrlHandler urlHandler)
     throws IntentNotResolvableException {
   final String errorMessage = "Unable to load mopub native browser url: " + uri;
   try {
     final Intent intent = Intents.intentForNativeBrowserScheme(uri);
     Intents.launchIntentForUserClick(context, intent, errorMessage);
   } catch (UrlParseException e) {
     throw new IntentNotResolvableException(errorMessage + "\n\t" + e.getMessage());
   }
 }
 @Override
 protected void performAction(
     @NonNull final Context context,
     @NonNull final Uri uri,
     @NonNull final UrlHandler urlHandler)
     throws IntentNotResolvableException {
   Intents.launchApplicationUrl(context, uri);
 }
    @Override
    protected void performAction(
        @NonNull final Context context,
        @NonNull final Uri uri,
        @NonNull final UrlHandler urlHandler)
        throws IntentNotResolvableException {
      Preconditions.checkNotNull(context);
      Preconditions.checkNotNull(uri);

      final String chooserText = "Share via";
      final String errorMessage = "Could not handle share tweet intent with URI " + uri;
      try {
        final Intent shareTweetIntent = Intents.intentForShareTweet(uri);
        final Intent chooserIntent = Intent.createChooser(shareTweetIntent, chooserText);
        Intents.launchIntentForUserClick(context, chooserIntent, errorMessage);
      } catch (UrlParseException e) {
        throw new IntentNotResolvableException(errorMessage + "\n\t" + e.getMessage());
      }
    }
 @Override
 protected void performAction(
     @NonNull final Context context,
     @NonNull final Uri uri,
     @NonNull final UrlHandler urlHandler)
     throws IntentNotResolvableException {
   if (!urlHandler.shouldSkipShowMoPubBrowser()) {
     Intents.showMoPubBrowserForUrl(context, uri);
   }
 }
 @Override
 protected void performAction(
     @NonNull final Context context,
     @NonNull final Uri uri,
     @NonNull final UrlHandler urlHandler)
     throws IntentNotResolvableException {
   final String errorMessage =
       "Could not handle intent with URI: "
           + uri
           + "\n\tIs "
           + "this intent supported on your phone?";
   Intents.launchActionViewIntent(context, uri, errorMessage);
 }
    @Override
    protected void performAction(
        @NonNull final Context context,
        @NonNull final Uri uri,
        @NonNull final UrlHandler urlHandler)
        throws IntentNotResolvableException {

      // 1. Parse the URL as a valid deeplink+
      if (!"navigate".equalsIgnoreCase(uri.getHost())) {
        throw new IntentNotResolvableException(
            "Deeplink+ URL did not have 'navigate' as" + " the host.");
      }

      final String primaryUrl;
      final List<String> primaryTrackingUrls;
      final String fallbackUrl;
      final List<String> fallbackTrackingUrls;
      try {
        primaryUrl = uri.getQueryParameter("primaryUrl");
        primaryTrackingUrls = uri.getQueryParameters("primaryTrackingUrl");
        fallbackUrl = uri.getQueryParameter("fallbackUrl");
        fallbackTrackingUrls = uri.getQueryParameters("fallbackTrackingUrl");
      } catch (UnsupportedOperationException e) {
        // If the URL is not hierarchical, getQueryParameter[s] will throw
        // UnsupportedOperationException (see
        // http://developer.android.com/reference/android/net/Uri.html#getQueryParameter(java.lang.String)
        throw new IntentNotResolvableException("Deeplink+ URL was not a hierarchical" + " URI.");
      }

      if (primaryUrl == null) {
        throw new IntentNotResolvableException(
            "Deeplink+ did not have 'primaryUrl' query" + " param.");
      }

      final Uri primaryUri = Uri.parse(primaryUrl);
      if (shouldTryHandlingUrl(primaryUri)) {
        // Nested Deeplink+ URLs are not allowed
        throw new IntentNotResolvableException(
            "Deeplink+ had another Deeplink+ as the " + "'primaryUrl'.");
      }

      // 2. Attempt to handle the primary URL
      try {
        Intents.launchApplicationUrl(context, primaryUri);
        makeTrackingHttpRequest(primaryTrackingUrls, context, BaseEvent.Name.CLICK_REQUEST);
        return;
      } catch (IntentNotResolvableException e) {
        // Primary URL failed; proceed to attempt fallback URL
      }

      // 3. Attempt to handle the fallback URL
      if (fallbackUrl == null) {
        throw new IntentNotResolvableException(
            "Unable to handle 'primaryUrl' for " + "Deeplink+ and 'fallbackUrl' was missing.");
      }

      if (shouldTryHandlingUrl(Uri.parse(fallbackUrl))) {
        // Nested Deeplink+ URLs are not allowed
        throw new IntentNotResolvableException(
            "Deeplink+ URL had another Deeplink+ " + "URL as the 'fallbackUrl'.");
      }

      // UrlAction.handleUrl already verified this comes from a user interaction
      final boolean fromUserInteraction = true;
      urlHandler.handleUrl(context, fallbackUrl, true, fallbackTrackingUrls);
    }