Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: does CustomTabsIntent support setPackageName()? #32

Closed
petrosmm opened this issue Feb 5, 2019 · 3 comments
Closed

Question: does CustomTabsIntent support setPackageName()? #32

petrosmm opened this issue Feb 5, 2019 · 3 comments

Comments

@petrosmm
Copy link

petrosmm commented Feb 5, 2019

Was working on a piece of code and I was under the impression that CustomTabsIntent could setPackageName() using customTabsIntent.intent.setPackageName("com.google.android.youtube"). Can anyone confirm if I am missing something... I had to put it in this form because I could setPackageName but it wouldn't work.

  Intent intent = null;
                    try {
                        intent = new Intent(Intent.ACTION_VIEW);
                        intent.setPackage("com.google.android.youtube");
                        intent.setData(Uri.parse(url));
                        startActivity(intent);
                    } catch (ActivityNotFoundException e) {
                        CustomTabsIntent customTabsIntent = new CustomTabsIntent
                                .Builder()
                                .addDefaultShareMenuItem()
                                .setToolbarColor(view.getContext().getResources().getColor(R.color.colorPrimary))
                                .setShowTitle(true)
                                //  .setCloseButtonIcon(backArrow)
                                .build();

                        // This is optional but recommended
                        CustomTabsHelper.addKeepAliveExtra(view.getContext(), customTabsIntent.intent);

                        // This is where the magic happens...
                        CustomTabsHelper.openCustomTab(view.getContext(), customTabsIntent,
                                Uri.parse(url),
                                new WebViewFallback());
                    }
@saschpe
Copy link
Owner

saschpe commented Feb 7, 2019

The built intent hold by CustomTabsIntent has a setPackage method, see https://developer.android.com/reference/android/content/Intent.html#setPackage(java.lang.String)

@petrosmm
Copy link
Author

petrosmm commented Feb 7, 2019

I tried that using customTabsIntent.intent.setPackageName("com.google.android.youtube") but it doesn't seem to work unless I use a plain old intent.... Any thoughts? I will try again, make sure I am not going crazy and double confirm.

@petrosmm
Copy link
Author

I guess I got it working, but I don't know how, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants