androidx.browser.customtabs.CustomTabsIntent Java Examples

The following examples show how to use androidx.browser.customtabs.CustomTabsIntent. 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: AuthorizationServiceTest.java    From AppAuth-Android with Apache License 2.0 6 votes vote down vote up
@Before
@SuppressWarnings("ResourceType")
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    mAuthCallback = new AuthorizationCallback();
    mRegistrationCallback = new RegistrationCallback();
    mBrowserDescriptor = Browsers.Chrome.customTab("46");
    mService = new AuthorizationService(
            mContext,
            new Builder()
                    .setConnectionBuilder(mConnectionBuilder)
                    .build(),
            mBrowserDescriptor,
            mCustomTabManager);
    mOutputStream = new ByteArrayOutputStream();
    when(mConnectionBuilder.openConnection(any(Uri.class))).thenReturn(mHttpConnection);
    when(mHttpConnection.getOutputStream()).thenReturn(mOutputStream);
    when(mContext.bindService(serviceIntentEq(), any(CustomTabsServiceConnection.class),
            anyInt())).thenReturn(true);
    when(mCustomTabManager.createTabBuilder())
            .thenReturn(new CustomTabsIntent.Builder());
}
 
Example #2
Source File: CustomTabActivityHelper.java    From Easy_xkcd with Apache License 2.0 6 votes vote down vote up
/**
 * Opens the URL on a Custom Tab if possible. Otherwise fallsback to opening it on a WebView
 *
 * @param activity The host activity
 * @param customTabsIntent a CustomTabsIntent to be used if Custom Tabs is available
 * @param uri the Uri to be opened
 * @param fallback a CustomTabFallback to be used if Custom Tabs is not available
 */
public static void openCustomTab(Activity activity,
                                 CustomTabsIntent customTabsIntent,
                                 Uri uri,
                                 CustomTabFallback fallback) {
    String packageName = CustomTabsHelper.getPackageNameToUse(activity);

    //If we cant find a package name, it means there's no browser that supports
    //Chrome Custom Tabs installed. So, we fallback to the webview
    if (packageName == null) {
        if (fallback != null) {
            fallback.openUri(activity, uri);
        }
    } else {
        customTabsIntent.intent.setPackage(packageName);
        customTabsIntent.launchUrl(activity, uri);
    }
}
 
Example #3
Source File: AppUtils.java    From materialistic with Apache License 2.0 6 votes vote down vote up
@NonNull
private static Intent createViewIntent(Context context, @Nullable WebItem item,
                                       String url, @Nullable CustomTabsSession session) {
    if (Preferences.customTabsEnabled(context)) {
        CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(session)
                .setToolbarColor(ContextCompat.getColor(context,
                        AppUtils.getThemedResId(context, R.attr.colorPrimary)))
                .setShowTitle(true)
                .enableUrlBarHiding()
                .addDefaultShareMenuItem();
        if (item != null) {
            builder.addMenuItem(context.getString(R.string.comments),
                    PendingIntent.getActivity(context, 0,
                            new Intent(context, ItemActivity.class)
                                    .putExtra(ItemActivity.EXTRA_ITEM, item)
                                    .putExtra(ItemActivity.EXTRA_OPEN_COMMENTS, true),
                            PendingIntent.FLAG_ONE_SHOT));
        }
        return builder.build().intent.setData(Uri.parse(url));
    } else {
        return new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    }
}
 
Example #4
Source File: NotificationParentActivity.java    From android-browser-helper with Apache License 2.0 6 votes vote down vote up
private void startChromeCustomTab(Intent intent) {
    String url = intent.getStringExtra(EXTRA_URL);
    if (url != null) {
        Uri uri = Uri.parse(url);

        int tabcolor = getResources().getColor(R.color.primaryColor);
        CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder()
                .setToolbarColor(tabcolor)
                .build();
        CustomTabActivityHelper.openCustomTab(
                this, customTabsIntent, uri, new WebviewFallback());

        mMessageTextView.setVisibility(View.VISIBLE);
        mCreateNotificationButton.setVisibility(View.GONE);
    } else {
        mMessageTextView.setVisibility(View.GONE);
        mCreateNotificationButton.setVisibility(View.VISIBLE);
    }
}
 
Example #5
Source File: ServiceConnectionActivity.java    From android-browser-helper with Apache License 2.0 6 votes vote down vote up
@Override
public void onClick(View view) {
    int viewId = view.getId();
    Uri uri  = Uri.parse(mUrlEditText.getText().toString());
    switch (viewId) {
        case R.id.button_may_launch_url:
            customTabActivityHelper.mayLaunchUrl(uri, null, null);
            break;
        case R.id.start_custom_tab:
            CustomTabsIntent customTabsIntent =
                    new CustomTabsIntent.Builder(customTabActivityHelper.getSession())
                    .build();
            CustomTabActivityHelper.openCustomTab(
                    this, customTabsIntent, uri, new WebviewFallback());
            break;
        default:
            //Unkown View Clicked
    }
}
 
Example #6
Source File: CustomTabActivityHelper.java    From android-browser-helper with Apache License 2.0 6 votes vote down vote up
/**
 * Opens the URL on a Custom Tab if possible. Otherwise fallsback to opening it on a WebView.
 *
 * @param activity The host activity.
 * @param customTabsIntent a CustomTabsIntent to be used if Custom Tabs is available.
 * @param uri the Uri to be opened.
 * @param fallback a CustomTabFallback to be used if Custom Tabs is not available.
 */
public static void openCustomTab(Activity activity,
                                 CustomTabsIntent customTabsIntent,
                                 Uri uri,
                                 CustomTabFallback fallback) {
    String packageName = CustomTabsHelper.getPackageNameToUse(activity);

    //If we cant find a package name, it means theres no browser that supports
    //Chrome Custom Tabs installed. So, we fallback to the webview
    if (packageName == null) {
        if (fallback != null) {
            fallback.openUri(activity, uri);
        }
    } else {
        customTabsIntent.intent.setPackage(packageName);
        customTabsIntent.launchUrl(activity, uri);
    }
}
 
Example #7
Source File: MainActivity.java    From android-browser-helper with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    String providerName = CustomTabsClient.getPackageName(this, null);
    SharedPreferencesTokenStore store = new SharedPreferencesTokenStore(this);

    // TODO: Add a button to clear the verified provider.

    findViewById(R.id.launch_browser).setOnClickListener(view -> {
        CustomTabsIntent intent = new CustomTabsIntent.Builder().build();

        intent.intent.setPackage(providerName);
        store.setVerifiedProvider(providerName, getPackageManager());

        intent.launchUrl(this, WEB_STORE);
    });
}
 
Example #8
Source File: ChromeCustomTabs.java    From leafpicrevived with GNU General Public License v3.0 6 votes vote down vote up
private void initService() {

        serviceConnection = new CustomTabsServiceConnection() {
            @Override
            public void onCustomTabsServiceConnected(ComponentName componentName, CustomTabsClient customTabsClient) {
                customTabsClient.warmup(0L);
            }

            @Override
            public void onServiceDisconnected(ComponentName name) {
                // NO-OP
            }
        };

        // Bind the Chrome Custom Tabs service
        CustomTabsClient.bindCustomTabsService(context, ApplicationUtils.getPackageName(), serviceConnection);

        mCustomTabsIntent = new CustomTabsIntent.Builder()
                .setShowTitle(true)
                .setToolbarColor(toolbarColor)
                .build();
    }
 
Example #9
Source File: SystemBarColorPredictor.java    From android-browser-helper with Apache License 2.0 6 votes vote down vote up
/**
 * Makes a best-effort guess about which navigation bar color will be used when the Trusted Web
 * Activity is launched. Returns null if not possible to predict.
 */
@Nullable
Integer getExpectedNavbarColor(Context context, String providerPackage,
        TrustedWebActivityIntentBuilder builder) {
    Intent intent = builder.buildCustomTabsIntent().intent;
    if (providerSupportsNavBarColorCustomization(context, providerPackage)) {
        if (providerSupportsColorSchemeParams(context, providerPackage)) {
            int colorScheme = getExpectedColorScheme(context, builder);
            CustomTabColorSchemeParams params = CustomTabsIntent.getColorSchemeParams(intent,
                    colorScheme);
            return params.navigationBarColor;
        }
        Bundle extras = intent.getExtras();
        return extras == null ? null :
                (Integer) extras.get(CustomTabsIntent.EXTRA_NAVIGATION_BAR_COLOR);
    }
    if (ChromeLegacyUtils.usesWhiteNavbar(providerPackage)) {
        return Color.WHITE;
    }
    return null;
}
 
Example #10
Source File: SettingsActivity.java    From MaxLock with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.toolbar_info:
            @SuppressWarnings("deprecation") CustomTabsIntent intent = new CustomTabsIntent.Builder(ctSession)
                    .setShowTitle(true)
                    .enableUrlBarHiding()
                    .setToolbarColor(getResources().getColor(R.color.primary_red))
                    .build();
            intent.launchUrl(this, Common.WEBSITE_URI);
            return true;
        case android.R.id.home:
            onBackPressed();
            return false;
        default:
            return false;
    }
}
 
Example #11
Source File: ChatAdapter.java    From Twire with GNU General Public License v3.0 6 votes vote down vote up
private void checkForLink(String message, SpannableStringBuilder spanbuilder) {
    Matcher linkMatcher = Patterns.WEB_URL.matcher(message);
    while (linkMatcher.find()) {
        String url = linkMatcher.group(0);

        if (!url.matches("^https?://.+"))
            url = "http://" + url;

        final String finalUrl = url;
        ClickableSpan clickableSpan = new ClickableSpan() {
            @Override
            public void onClick(View view) {
                CustomTabsIntent.Builder mTabs = new CustomTabsIntent.Builder();
                mTabs.setStartAnimations(context, R.anim.slide_in_bottom_anim, R.anim.fade_out_semi_anim);
                mTabs.setExitAnimations(context, R.anim.fade_in_semi_anim, R.anim.slide_out_bottom_anim);
                mTabs.build().launchUrl(context, Uri.parse(finalUrl));

                mRecyclerView.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
            }
        };

        spanbuilder.setSpan(clickableSpan, linkMatcher.start(), linkMatcher.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}
 
Example #12
Source File: AuthorizationService.java    From AppAuth-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Sends an authorization request to the authorization service, using a
 * [custom tab](https://developer.chrome.com/multidevice/android/customtabs).
 * The parameters of this request are determined by both the authorization service
 * configuration and the provided {@link AuthorizationRequest request object}. Upon completion
 * of this request, the provided {@link PendingIntent completion PendingIntent} will be invoked.
 * If the user cancels the authorization request, the provided
 * {@link PendingIntent cancel PendingIntent} will be invoked.
 *
 * @param customTabsIntent
 *     The intent that will be used to start the custom tab. It is recommended that this intent
 *     be created with the help of {@link #createCustomTabsIntentBuilder(Uri[])}, which will
 *     ensure that a warmed-up version of the browser will be used, minimizing latency.
 *
 * @throws android.content.ActivityNotFoundException if no suitable browser is available to
 *     perform the authorization flow.
 */
public void performAuthorizationRequest(
        @NonNull AuthorizationRequest request,
        @NonNull PendingIntent completedIntent,
        @Nullable PendingIntent canceledIntent,
        @NonNull CustomTabsIntent customTabsIntent) {
    checkNotDisposed();
    checkNotNull(request);
    checkNotNull(completedIntent);
    checkNotNull(customTabsIntent);

    Intent authIntent = prepareAuthorizationRequestIntent(request, customTabsIntent);
    mContext.startActivity(AuthorizationManagementActivity.createStartIntent(
            mContext,
            request,
            authIntent,
            completedIntent,
            canceledIntent));
}
 
Example #13
Source File: MainActivity.java    From pandora with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    String url = "https://github.com/whataa/pandora";
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        Uri githubUrl = Uri.parse(url);
        intent.setData(githubUrl);
        if (intent.resolveActivity(getPackageManager()) != null) {
            startActivity(intent);
        }
    } else {
        CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
        builder.setToolbarColor(getResources().getColor(R.color.colorPrimary));
        CustomTabsIntent customTabsIntent = builder.build();
        customTabsIntent.launchUrl(this, Uri.parse(url));
    }
    return true;
}
 
Example #14
Source File: PostListAdapter.java    From indigenous-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onClick(View v) {
    PostListItem item = items.get(this.position);

    try {
        CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
        intentBuilder.setToolbarColor(ContextCompat.getColor(context, R.color.colorPrimary));
        intentBuilder.setSecondaryToolbarColor(ContextCompat.getColor(context, R.color.colorPrimaryDark));
        CustomTabsIntent customTabsIntent = intentBuilder.build();
        customTabsIntent.intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        customTabsIntent.launchUrl(context, Uri.parse(item.getUrl()));
    }
    catch (Exception ignored) { }

}
 
Example #15
Source File: TimelineDetailActivity.java    From indigenous-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Link clickable.
 *
 * @param strBuilder
 *   A string builder.
 * @param span
 *   The span with url.
 */
private void makeLinkClickable(SpannableStringBuilder strBuilder, final URLSpan span) {
    int start = strBuilder.getSpanStart(span);
    int end = strBuilder.getSpanEnd(span);
    int flags = strBuilder.getSpanFlags(span);
    ClickableSpan clickable = new ClickableSpan() {
        public void onClick(@NonNull View view) {
            try {
                CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
                intentBuilder.setToolbarColor(ContextCompat.getColor(TimelineDetailActivity.this, R.color.colorPrimary));
                intentBuilder.setSecondaryToolbarColor(ContextCompat.getColor(TimelineDetailActivity.this, R.color.colorPrimaryDark));
                CustomTabsIntent customTabsIntent = intentBuilder.build();
                customTabsIntent.intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                customTabsIntent.launchUrl(TimelineDetailActivity.this, Uri.parse(span.getURL()));
            }
            catch (Exception ignored) { }
        }
    };
    strBuilder.setSpan(clickable, start, end, flags);
    strBuilder.removeSpan(span);
}
 
Example #16
Source File: TimelineListAdapter.java    From indigenous-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Link clickable.
 *
 * @param strBuilder
 *   A string builder.
 * @param span
 *   The span with url.
 */
private void makeLinkClickable(SpannableStringBuilder strBuilder, final URLSpan span) {
    int start = strBuilder.getSpanStart(span);
    int end = strBuilder.getSpanEnd(span);
    int flags = strBuilder.getSpanFlags(span);
    ClickableSpan clickable = new ClickableSpan() {
        public void onClick(View view) {
            try {
                CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
                intentBuilder.setToolbarColor(ContextCompat.getColor(context, R.color.colorPrimary));
                intentBuilder.setSecondaryToolbarColor(ContextCompat.getColor(context, R.color.colorPrimaryDark));
                CustomTabsIntent customTabsIntent = intentBuilder.build();
                customTabsIntent.intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                customTabsIntent.launchUrl(context, Uri.parse(span.getURL()));
            }
            catch (Exception ignored) { }
        }
    };
    strBuilder.setSpan(clickable, start, end, flags);
    strBuilder.removeSpan(span);
}
 
Example #17
Source File: TimelineListAdapter.java    From indigenous-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onClick(View v) {
    TimelineItem item = items.get(this.position);

    try {
        CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
        intentBuilder.setToolbarColor(ContextCompat.getColor(context, R.color.colorPrimary));
        intentBuilder.setSecondaryToolbarColor(ContextCompat.getColor(context, R.color.colorPrimaryDark));
        CustomTabsIntent customTabsIntent = intentBuilder.build();
        customTabsIntent.intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        customTabsIntent.launchUrl(context, Uri.parse(item.getUrl()));
    }
    catch (Exception ignored) { }

}
 
Example #18
Source File: QiscusBaseLinkViewHolder.java    From qiscus-sdk-android with Apache License 2.0 6 votes vote down vote up
private void setUpLinks() {
    String message = messageTextView.getText().toString();
    Matcher matcher = PatternsCompat.AUTOLINK_WEB_URL.matcher(message);
    while (matcher.find()) {
        int start = matcher.start();
        if (start > 0 && message.charAt(start - 1) == '@') {
            continue;
        }
        int end = matcher.end();
        clickify(start, end, () -> {
            String url = message.substring(start, end);
            if (!url.startsWith("http")) {
                url = "http://" + url;
            }
            new CustomTabsIntent.Builder()
                    .setToolbarColor(ContextCompat.getColor(Qiscus.getApps(), Qiscus.getChatConfig().getAppBarColor()))
                    .setShowTitle(true)
                    .addDefaultShareMenuItem()
                    .enableUrlBarHiding()
                    .build()
                    .launchUrl(messageTextView.getContext(), Uri.parse(url));
        });
    }
}
 
Example #19
Source File: QiscusBaseImageMessageViewHolder.java    From qiscus-sdk-android with Apache License 2.0 6 votes vote down vote up
private void setUpLinks() {
    String message = captionView.getText().toString();
    Matcher matcher = PatternsCompat.AUTOLINK_WEB_URL.matcher(message);
    while (matcher.find()) {
        int start = matcher.start();
        if (start > 0 && message.charAt(start - 1) == '@') {
            continue;
        }
        int end = matcher.end();
        clickify(start, end, () -> {
            String url = message.substring(start, end);
            if (!url.startsWith("http")) {
                url = "http://" + url;
            }
            new CustomTabsIntent.Builder()
                    .setToolbarColor(ContextCompat.getColor(Qiscus.getApps(), Qiscus.getChatConfig().getAppBarColor()))
                    .setShowTitle(true)
                    .addDefaultShareMenuItem()
                    .enableUrlBarHiding()
                    .build()
                    .launchUrl(captionView.getContext(), Uri.parse(url));
        });
    }
}
 
Example #20
Source File: QiscusBaseReplyMessageViewHolder.java    From qiscus-sdk-android with Apache License 2.0 6 votes vote down vote up
private void setUpLinks() {
    String message = messageTextView.getText().toString();
    Matcher matcher = PatternsCompat.AUTOLINK_WEB_URL.matcher(message);
    while (matcher.find()) {
        int start = matcher.start();
        if (start > 0 && message.charAt(start - 1) == '@') {
            continue;
        }
        int end = matcher.end();
        clickify(start, end, () -> {
            String url = message.substring(start, end);
            if (!url.startsWith("http")) {
                url = "http://" + url;
            }
            new CustomTabsIntent.Builder()
                    .setToolbarColor(ContextCompat.getColor(Qiscus.getApps(), Qiscus.getChatConfig().getAppBarColor()))
                    .setShowTitle(true)
                    .addDefaultShareMenuItem()
                    .enableUrlBarHiding()
                    .build()
                    .launchUrl(messageTextView.getContext(), Uri.parse(url));
        });
    }
}
 
Example #21
Source File: ChatAdapter.java    From Pocket-Plays-for-Twitch with GNU General Public License v3.0 6 votes vote down vote up
private void checkForLink(String message, SpannableStringBuilder spanbuilder) {
	linkMatcher = linkPattern.matcher(message);
	while(linkMatcher.find()) {
		final String url = linkMatcher.group(1);

		ClickableSpan clickableSpan = new ClickableSpan() {
			@Override
			public void onClick(View view) {
				CustomTabsIntent.Builder mTabs = new CustomTabsIntent.Builder();
				mTabs.setStartAnimations(context, R.anim.slide_in_bottom_anim, R.anim.fade_out_semi_anim);
				mTabs.setExitAnimations(context, R.anim.fade_in_semi_anim, R.anim.slide_out_bottom_anim);
				mTabs.build().launchUrl(context, Uri.parse(url));

				mRecyclerView.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
			}
		};

		int start = message.indexOf(url);
		spanbuilder.setSpan(clickableSpan, start, start + url.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
	}
}
 
Example #22
Source File: LaunchActivity.java    From intra42 with Apache License 2.0 6 votes vote down vote up
public void onLoginClick(View view) {
    Analytics.signInAttempt();
    Uri loginUri = Uri.parse(ApiService.API_BASE_URL + "/oauth/authorize?client_id=" + Credential.UID + "&redirect_uri=" + Credential.API_OAUTH_REDIRECT + "&response_type=code&scope=" + Credential.SCOPE);

    CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
    builder.setShowTitle(true);
    builder.setInstantAppsEnabled(true);

    Intent defaultBrowserIntent = new Intent(Intent.ACTION_VIEW);
    defaultBrowserIntent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    defaultBrowserIntent.setData(loginUri);
    PendingIntent defaultBrowserPendingIntent = PendingIntent.getActivity(this, 0, defaultBrowserIntent, 0);

    builder.addMenuItem(getString(R.string.login_custom_chrome_tabs_open_default_browser), defaultBrowserPendingIntent);
    CustomTabsIntent customTabsIntent = builder.build();
    customTabsIntent.intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    try {
        customTabsIntent.launchUrl(this, loginUri);
    } catch (ActivityNotFoundException e) {
        e.printStackTrace();
        FirebaseCrashlytics.getInstance().recordException(e);
        Toast.makeText(app, R.string.login_error_web_browser_required, Toast.LENGTH_SHORT).show();
    }
}
 
Example #23
Source File: CustomTabTest.java    From focus-android with Mozilla Public License 2.0 6 votes vote down vote up
private Intent createCustomTabIntent() {
    final Context appContext = InstrumentationRegistry.getInstrumentation()
            .getTargetContext()
            .getApplicationContext();

    final PendingIntent pendingIntent = PendingIntent.getActivity(appContext, 0, new Intent(), 0);

    final CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder()
            .addMenuItem(MENU_ITEM_LABEL, pendingIntent)
            .addDefaultShareMenuItem()
            .setActionButton(createTestBitmap(), ACTION_BUTTON_DESCRIPTION, pendingIntent, true)
            .setToolbarColor(Color.MAGENTA)
            .build();

    customTabsIntent.intent.setData(Uri.parse(webServer.url("/").toString()));

    return customTabsIntent.intent;
}
 
Example #24
Source File: CustomTabsHelper.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Injects Referrers to the intent so they can be extracted by the url source.
 * This way the url source can see that we are generating traffic to their page.
 */
private void addRefererHttpHeader(Context context, CustomTabsIntent customTabsIntent) {
  Bundle httpHeaders = new Bundle();
  httpHeaders.putString("Referer", "http://m.aptoide.com");
  customTabsIntent.intent.putExtra(Browser.EXTRA_HEADERS, httpHeaders);
  customTabsIntent.intent.getExtras();
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
    customTabsIntent.intent.putExtra(Intent.EXTRA_REFERRER_NAME,
        "android-app://" + context.getPackageName() + "/");
  }
}
 
Example #25
Source File: CustomTabsHelper.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
@NonNull private CustomTabsIntent.Builder getBuilder(Context context, int color) {
  Intent openInNativeIntent =
      new Intent(context.getApplicationContext(), CustomTabNativeReceiver.class);
  PendingIntent pendingIntent =
      PendingIntent.getBroadcast(context.getApplicationContext(), 0, openInNativeIntent, 0);
  return new CustomTabsIntent.Builder().setToolbarColor(ContextCompat.getColor(context, color))
      .setShowTitle(true)
      .setCloseButtonIcon(
          BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_arrow_back))
      .addDefaultShareMenuItem()
      .addMenuItem(context.getString(R.string.customtabs_open_native_app), pendingIntent)
      .setStartAnimations(context, R.anim.slide_in_right, R.anim.slide_out_left)
      .setExitAnimations(context, R.anim.slide_in_left, R.anim.slide_out_right);
}
 
Example #26
Source File: QiscusBaseCardMessageViewHolder.java    From qiscus-sdk-android with Apache License 2.0 5 votes vote down vote up
private void openLink(String url) {
    new CustomTabsIntent.Builder()
            .setToolbarColor(ContextCompat.getColor(Qiscus.getApps(), Qiscus.getChatConfig().getAppBarColor()))
            .setShowTitle(true)
            .addDefaultShareMenuItem()
            .enableUrlBarHiding()
            .build()
            .launchUrl(messageTextView.getContext(), Uri.parse(url));
}
 
Example #27
Source File: QiscusLinkPreviewView.java    From qiscus-sdk-android with Apache License 2.0 5 votes vote down vote up
private void openUrl() {
    new CustomTabsIntent.Builder()
            .setToolbarColor(ContextCompat.getColor(getContext(), Qiscus.getChatConfig().getAppBarColor()))
            .setShowTitle(true)
            .addDefaultShareMenuItem()
            .enableUrlBarHiding()
            .build()
            .launchUrl(getContext(), Uri.parse(previewData.getUrl()));
}
 
Example #28
Source File: AboutShortcuts.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
private static void openUrl(Context ctx, String url) {
    try {
        CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
        builder.setToolbarColor(ctx.getResources().getColor(R.color.colorPrimary));
        CustomTabsIntent customTabsIntent = builder.build();
        customTabsIntent.launchUrl(ctx, Uri.parse(url));
    } catch (ActivityNotFoundException e) {
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(url));
        ctx.startActivity(i);
    }
}
 
Example #29
Source File: QiscusCarouselItemView.java    From qiscus-sdk-android with Apache License 2.0 5 votes vote down vote up
private void openLink(String url) {
    new CustomTabsIntent.Builder()
            .setToolbarColor(ContextCompat.getColor(Qiscus.getApps(), Qiscus.getChatConfig().getAppBarColor()))
            .setShowTitle(true)
            .addDefaultShareMenuItem()
            .enableUrlBarHiding()
            .build()
            .launchUrl(getContext(), Uri.parse(url));
}
 
Example #30
Source File: PUI.java    From PHONK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Shows a web in a different screen.
 * Once the web is opened, we loose the control of the script
 *
 * @param url
 * @status TOREVIEW
 * @advanced
 */
@PhonkMethod
public void showWeb(String url) {
    CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
    builder.setToolbarColor(Color.BLUE);
    builder.addDefaultShareMenuItem();
    builder.setInstantAppsEnabled(true);

    // builder.setStartAnimations(this, R.anim.slide_in_right, R.anim.slide_out_left);
    // builder.setExitAnimations(this, R.anim.slide_in_left, R.anim.slide_out_right);

    CustomTabsIntent customTabsIntent = builder.build();
    customTabsIntent.launchUrl(getActivity(), Uri.parse(url));
}