@Test(expected = UrlParseException.class) public void intentForShareTweetScheme_whenScreenNameParameterIsEmpty_shouldThrowException() throws UrlParseException { Intents.intentForShareTweet(Uri.parse("mopubshare: }
public static Intent intentForShareTweet(@NonNull final Uri uri) throws UrlParseException { if (!UrlAction.HANDLE_SHARE_TWEET.shouldTryHandlingUrl(uri)) { throw new UrlParseException("URL does not have mopubshare: } final String screenName; final String tweetId; try { screenName = uri.getQueryParameter("screen_name"); tweetId = uri.getQueryParameter("tweet_id"); } catch (UnsupportedOperationException e) { MoPubLog.w("Could not handle url: " + uri); throw new UrlParseException("Passed-in URL did not create a hierarchical URI."); } if (TextUtils.isEmpty(screenName)) { throw new UrlParseException("URL missing non-empty 'screen_name' query parameter."); } if (TextUtils.isEmpty(tweetId)) { throw new UrlParseException("URL missing non-empty 'tweet_id' query parameter."); } final String tweetUrl = String.format("https: final String shareMessage = String.format("Check out @%s's Tweet: %s", screenName, tweetUrl); Intent shareTweetIntent = new Intent(Intent.ACTION_SEND); shareTweetIntent.setType("text/plain"); shareTweetIntent.putExtra(Intent.EXTRA_SUBJECT, shareMessage); shareTweetIntent.putExtra(Intent.EXTRA_TEXT, shareMessage); return shareTweetIntent; }
Intents { public static Intent intentForShareTweet(@NonNull final Uri uri) throws UrlParseException { if (!UrlAction.HANDLE_SHARE_TWEET.shouldTryHandlingUrl(uri)) { throw new UrlParseException("URL does not have mopubshare: } final String screenName; final String tweetId; try { screenName = uri.getQueryParameter("screen_name"); tweetId = uri.getQueryParameter("tweet_id"); } catch (UnsupportedOperationException e) { MoPubLog.w("Could not handle url: " + uri); throw new UrlParseException("Passed-in URL did not create a hierarchical URI."); } if (TextUtils.isEmpty(screenName)) { throw new UrlParseException("URL missing non-empty 'screen_name' query parameter."); } if (TextUtils.isEmpty(tweetId)) { throw new UrlParseException("URL missing non-empty 'tweet_id' query parameter."); } final String tweetUrl = String.format("https: final String shareMessage = String.format("Check out @%s's Tweet: %s", screenName, tweetUrl); Intent shareTweetIntent = new Intent(Intent.ACTION_SEND); shareTweetIntent.setType("text/plain"); shareTweetIntent.putExtra(Intent.EXTRA_SUBJECT, shareMessage); shareTweetIntent.putExtra(Intent.EXTRA_TEXT, shareMessage); return shareTweetIntent; } }
Intents { public static Intent intentForShareTweet(@NonNull final Uri uri) throws UrlParseException { if (!UrlAction.HANDLE_SHARE_TWEET.shouldTryHandlingUrl(uri)) { throw new UrlParseException("URL does not have mopubshare: } final String screenName; final String tweetId; try { screenName = uri.getQueryParameter("screen_name"); tweetId = uri.getQueryParameter("tweet_id"); } catch (UnsupportedOperationException e) { MoPubLog.w("Could not handle url: " + uri); throw new UrlParseException("Passed-in URL did not create a hierarchical URI."); } if (TextUtils.isEmpty(screenName)) { throw new UrlParseException("URL missing non-empty 'screen_name' query parameter."); } if (TextUtils.isEmpty(tweetId)) { throw new UrlParseException("URL missing non-empty 'tweet_id' query parameter."); } final String tweetUrl = String.format("https: final String shareMessage = String.format("Check out @%s's Tweet: %s", screenName, tweetUrl); Intent shareTweetIntent = new Intent(Intent.ACTION_SEND); shareTweetIntent.setType("text/plain"); shareTweetIntent.putExtra(Intent.EXTRA_SUBJECT, shareMessage); shareTweetIntent.putExtra(Intent.EXTRA_TEXT, shareMessage); return shareTweetIntent; } private  Intents(); }
Intents { public static Intent intentForShareTweet(@NonNull final Uri uri) throws UrlParseException { if (!UrlAction.HANDLE_SHARE_TWEET.shouldTryHandlingUrl(uri)) { throw new UrlParseException("URL does not have mopubshare: } final String screenName; final String tweetId; try { screenName = uri.getQueryParameter("screen_name"); tweetId = uri.getQueryParameter("tweet_id"); } catch (UnsupportedOperationException e) { MoPubLog.w("Could not handle url: " + uri); throw new UrlParseException("Passed-in URL did not create a hierarchical URI."); } if (TextUtils.isEmpty(screenName)) { throw new UrlParseException("URL missing non-empty 'screen_name' query parameter."); } if (TextUtils.isEmpty(tweetId)) { throw new UrlParseException("URL missing non-empty 'tweet_id' query parameter."); } final String tweetUrl = String.format("https: final String shareMessage = String.format("Check out @%s's Tweet: %s", screenName, tweetUrl); Intent shareTweetIntent = new Intent(Intent.ACTION_SEND); shareTweetIntent.setType("text/plain"); shareTweetIntent.putExtra(Intent.EXTRA_SUBJECT, shareMessage); shareTweetIntent.putExtra(Intent.EXTRA_TEXT, shareMessage); return shareTweetIntent; } private  Intents(); static void startActivity(@NonNull final Context context, @NonNull final Intent intent); static Intent getStartActivityIntent(@NonNull final Context context,
            @NonNull final Class clazz, @Nullable final Bundle extras); static boolean deviceCanHandleIntent(@NonNull final Context context,
            @NonNull final Intent intent); static boolean canHandleApplicationUrl(final Context context, final Uri uri); static boolean canHandleApplicationUrl(final Context context, final Uri uri,
            final boolean logError); static Intent intentForNativeBrowserScheme(@NonNull final Uri uri); static Intent intentForShareTweet(@NonNull final Uri uri); static void showMoPubBrowserForUrl(@NonNull final Context context,
            @NonNull Uri uri); static void launchActionViewIntent(Context context, @NonNull final Uri uri,
            @NonNull final String errorMessage); static void launchIntentForUserClick(@NonNull final Context context,
            @NonNull final Intent intent, @Nullable final String errorMessage); static void launchApplicationUrl(@NonNull final Context context,
            @NonNull final Uri uri); }
Intents { public static Intent intentForShareTweet(@NonNull final Uri uri) throws UrlParseException { if (!UrlAction.HANDLE_SHARE_TWEET.shouldTryHandlingUrl(uri)) { throw new UrlParseException("URL does not have mopubshare: } final String screenName; final String tweetId; try { screenName = uri.getQueryParameter("screen_name"); tweetId = uri.getQueryParameter("tweet_id"); } catch (UnsupportedOperationException e) { MoPubLog.w("Could not handle url: " + uri); throw new UrlParseException("Passed-in URL did not create a hierarchical URI."); } if (TextUtils.isEmpty(screenName)) { throw new UrlParseException("URL missing non-empty 'screen_name' query parameter."); } if (TextUtils.isEmpty(tweetId)) { throw new UrlParseException("URL missing non-empty 'tweet_id' query parameter."); } final String tweetUrl = String.format("https: final String shareMessage = String.format("Check out @%s's Tweet: %s", screenName, tweetUrl); Intent shareTweetIntent = new Intent(Intent.ACTION_SEND); shareTweetIntent.setType("text/plain"); shareTweetIntent.putExtra(Intent.EXTRA_SUBJECT, shareMessage); shareTweetIntent.putExtra(Intent.EXTRA_TEXT, shareMessage); return shareTweetIntent; } private  Intents(); static void startActivity(@NonNull final Context context, @NonNull final Intent intent); static Intent getStartActivityIntent(@NonNull final Context context,
            @NonNull final Class clazz, @Nullable final Bundle extras); static boolean deviceCanHandleIntent(@NonNull final Context context,
            @NonNull final Intent intent); static boolean canHandleApplicationUrl(final Context context, final Uri uri); static boolean canHandleApplicationUrl(final Context context, final Uri uri,
            final boolean logError); static Intent intentForNativeBrowserScheme(@NonNull final Uri uri); static Intent intentForShareTweet(@NonNull final Uri uri); static void showMoPubBrowserForUrl(@NonNull final Context context,
            @NonNull Uri uri); static void launchActionViewIntent(Context context, @NonNull final Uri uri,
            @NonNull final String errorMessage); static void launchIntentForUserClick(@NonNull final Context context,
            @NonNull final Intent intent, @Nullable final String errorMessage); static void launchApplicationUrl(@NonNull final Context context,
            @NonNull final Uri uri);  }