https://kotlinlang.org logo
#android
Title
# android
m

myanmarking

08/14/2017, 8:56 AM
guys, is it safe to use google chrome tabs to replace webviews?
g

gildor

08/14/2017, 9:50 AM
Yes, it’s safe. It will be handled by CustomTabs SDK
m

myanmarking

08/14/2017, 9:50 AM
oh ok nice
thanks
g

gildor

08/14/2017, 9:52 AM
actually, CustomTabs generates completely valid android.intent.action.VIEW intent with additional arguments that works fine without custom tabs
m

myanmarking

08/14/2017, 9:52 AM
what if user has unninstalled chrome=?
is that possible
g

gildor

08/14/2017, 9:53 AM
There isn’t any chrome dependencies, it’s just view intent with additional params
you can decompile android.support.customtabs.CustomTabsIntent and check arguments of intent
m

myanmarking

08/14/2017, 9:54 AM
ok
thanks
i think
i disabled chrome in the settings
and now it crashes ..
g

gildor

08/14/2017, 9:57 AM
Are you sure that you restarted app? Maybe it’s some cached intent
m

myanmarking

08/14/2017, 9:57 AM
i didnt restart. 1s
g

gildor

08/14/2017, 9:57 AM
or maybe you have no any other browser in your system
s

scruffyfox

08/14/2017, 9:57 AM
AFAIK you do have to do a check if chrometabs is available before using
m

myanmarking

08/14/2017, 9:58 AM
restarted the app
still crashes
well in that case, i’ll use a custom library
dont want to handle multiple scenarios
g

gildor

08/14/2017, 9:58 AM
Do you have any browser on your device except chrome?
m

myanmarking

08/14/2017, 9:59 AM
dont think i have
1s
g

gildor

08/14/2017, 9:59 AM
Any application will crash with or without customtabs if you try to open VIEW intent for URL without browser
s

scruffyfox

08/14/2017, 10:00 AM
looks like the check is only for SDK_INT
m

myanmarking

08/14/2017, 10:00 AM
i emailed myself with a url, and it wont open
doesnt crash either, just dont open
g

gildor

08/14/2017, 10:00 AM
Custom tabs available starting from api level 16
so if your target API is 16 or greater you shouldn’t check
just dont open
because your email app checks for intent
m

myanmarking

08/14/2017, 10:02 AM
ok
g

gildor

08/14/2017, 10:02 AM
There are two ways: 1. launch and forget, in case if user have no browser or other application, that handles such links, your app will crash. 2. Check each external intent. There is API for that
m

myanmarking

08/14/2017, 10:02 AM
so i need to check for a viable browser then
sounds reasonable
g

gildor

08/14/2017, 10:02 AM
If you want, most application actually never do that. But it make sense of course
m

myanmarking

08/14/2017, 10:02 AM
gona try install another browser other than chrome and try
you right
firefox opens the tabs as well
i tought tabs were related to chrome and wud only work with chrome
g

gildor

08/14/2017, 10:08 AM
To check you need something like:
Copy code
customTabBuilder.build().intent.resolveActivity(context.packageManager) != null
but as I said, this check not related to custom tabs, it’s universal thing for Android and any external intent
m

myanmarking

08/14/2017, 10:15 AM
sounds logic
there a weird toast that shws up everytime user leaves the chrome tab and return to the app
something like “history stack was cleared”.
g

gildor

08/14/2017, 10:23 AM
Looks like some sort of “incognito mode” in browser, but actually never saw this message
a

anthonyeef

08/14/2017, 12:18 PM
in fact it’s possible user device don’t have chrome installed (just come china and you will find it’s quite a lot since this country block Google and a serious of related app. The stock rom of Android device has its custom rom, without anything related to Google
And if anyone want to make sure use ChromeCustomTab right and safe, the fallback solution should be considered
m

myanmarking

08/14/2017, 12:19 PM
doesn’t need to have chrome. it runs on another browsers isnt it?
i tried disabling chrome and it crashed. then installed firefox and it run
a

anthonyeef

08/14/2017, 12:20 PM
yeah it don’t really require chrome, it’s
intend
actually. I just tried it today morning, using a made in china mobile phone
And you can find some real nice library as I remember, there is a CustomTabHelper lib on github (may not exactly that name and you can search
m

myanmarking

08/14/2017, 12:21 PM
i’ll leave it with chrome tabs for now
latter i’ll switch to a custom library like finnestwebview
thanks for you help tho
g

gildor

08/14/2017, 1:15 PM
@anthonyeef But fallback solution already there! Right inside CustomTabs SDK. In case of no chrome or disabled custom tabs will be opened any exisitng browser.
@myanmarking Not any browser, but browser that supports custom tabs protocol. Not all browsers support it. And even if user has any browser or any other app that registered handler for http/https links this app will be opened if you use custom tabs
a

anthonyeef

08/14/2017, 1:27 PM
@gildor you are right
r

radityagumay

08/14/2017, 5:24 PM
A great discussion!!
7 Views