WebChromeClient Integrate in Android App - android

I'm trying to solve a problem in integrating WebChromeClient and try to achieve this one below (If possible).
Mine:
Steps that I made: I create an Activity with WebView in it. And just reflect the Url in the toolbar as title.
How can we somehow fuse (Fuse maybe not the right word) this to our App? The onCreateOptionsMenu is from Chrome Browser as I noticed.
EDIT: I don't know the name of it, I thought it is webChromeClient.

I don't know the exact name for this, I thought it was webChromeClient - but it is Chrome Custom Tabs. The documentation for implementations is found here:
https://developer.chrome.com/multidevice/android/customtabs#whatarethey
Gradle: compile 'com.android.support:customtabs:24.2.1'
Chrome Custom Tabs is faster than Google Chrome Browser and WebView.
Customization is also included
The WebView is good solution if you are hosting your own content inside your app. If your app directs people to URLs outside your domain, It is recommend that you use Chrome Custom Tabs for these reasons:
NOTE:
If there is no default browser set, it will pop up BottomSheet to complete action using. I think this should not be. We must check if Chrome browser is installed and launched that instead of other browser.

For kotlin users, equivalent is implementation 'androidx.browser:browser:1.0.0'
Sample code can be found at https://github.com/anandwana001/mindorks-cct

Related

Hide the location bar in Chrome Custom Tabs in MAUI

So that I don't ask the wrong question, my end goal is to build a PWA that is accessible from Android 5.x and up now and iOS later in the year. The main problem with this is Classic Bluetooth is not yet stable/standardized enough for the web.
My next plan was to build a "native" app (in .NET MAUI so that I can reuse parts in iOS) using a WebView for displaying the PWA and calling back to the native app for Bluetooth. The problem here is the WebView version on the devices I have to support doesn't support PWAs, service workers, etc. (upgrading the hundred or so hardware devices is not possible, upgrading the OS is not possible, and it's pre-Android-8 so upgrading WebView is not possible without a new ROM).
Finally I've tried installing Chrome via device management and using "Chrome Custom Tabs" from MAUI. The simplest implementation works:
// Browser is <IBrowser>Microsoft.Maui.ApplicationModel.Browser.Default
await Browser.OpenAsync(
"https://www.whatismybrowser.com/detect/what-is-my-user-agent/",
BrowserLaunchMode.SystemPreferred);
and the tab is displayed "in" my app, however the location bar is shown within the tab:
Which brings me to the question:
How do I use a Chrome Custom Tab from MAUI but hide the location bar? Is this even possible?
There's little to no documentation on this for MAUI. I've tried looking through the MAUI source, but all I can see are some options:
await Browser.OpenAsync("https://www.whatismybrowser.com/detect/what-is-my-user-agent/", new BrowserLaunchOptions
{
LaunchMode = BrowserLaunchMode.SystemPreferred, // open inside the MAUI app, i.e. Custom Tab
TitleMode = BrowserTitleMode.Hide, // doesn't seem to have any effect
Flags = BrowserLaunchFlags.LaunchAdjacent // the only Android flag
});
The LaunchAdjacent flag just opens "up" instead of sideways. The other flags are for iOS, detailed here. The TitleMode doesn't seem to do anything.
Reading about Chrome Custom Tabs here, it appears it's not possible, unless I own the destination URL and setup a Trusted Web Activity. Hosting a web app combined with a native app for Bluetooth may be the only way to go if I can't use a WebView.

Is it possible to display the Google Chrome browser from within an Android app?

I want my app to launch chrome but also monitor the user's actions on chrome, such as navigating, back, etc. I think I can launch chrome using Intents, but I'm not sure about monitoring user input.
With chrome application is not possible. For do that you must implement a webview within your own app.
Well you can try Custom Tabs
With Custom Tabs you can get instance of browser which support CustomTabs like chrome without creating a web view. As it provide navigation awareness, the browser delivers a callback to the application upon an external navigation. You can modify and update following -
Custom menu
Color of the address bar
Custom action button
Custom enter and exit animations
Check Custom Tabs Implementation Guide
You need to use Web view or create your own browser then you can achieve your goal.

Disable Chrome Options Menu - Android

I am trying to do SSO using Chrome Tabs in my Android Application.
Whenever the chrome comes in it also has options menu of chrome - Is there a way to disable this options menu.
Attached is a screenshot
No, currently is not possibile: you can add items but not remove the button.
https://developer.chrome.com/multidevice/android/customtabs
Simply use a WebView instead of CustomTabs - then there is nothing to hide away, to begin with.
In cases like this you should use phonegap instead of use chrome browser as webview read the docs
basically it runs chrome webview on android, and safari webview on IOS but without all chrome/safari options.
Hey there so in my opinion you should use simple Android webview if you don't want your user to access these options.
Just create a new activity/fragment that contains webview and open your website or any url within it.
This might help you from android developer docs.
Also try this example that might be useful.

Does Android's Stock Web Browser use WebViewClient?

If I understand correctly, every WebView based implementation needs WebViewClient.
But looking at the source code for Android 2.2's browser, I can't find any mention of WebViewClient.
How does it work if it doesn't use it?
If it does use it, where is it "hiding"?
It is implemented inside the tabs (see Tab.java).

Android webview to work like native browser

I experimenting with WebView in Android and I can't figure out how to make it work like the native browser.
I have an example for this:
Go to deviantART.com in native browser. Press Menu button. At the bottom of the menu there will be a link to disable mobile view and it works as expected. This exact same thing doesn't work in WebView. It simply turns the menu off and that is all, mobil CSS still stays intact.
I need to make users disable deviantART's mobile CSS, so I need the WebView to work like this.
JavaScript and DOMStorage are enabled.
I need the proper code or an workaround, but after hours of searching I didn't find anything that connected to this problem.
Thank you in advance.
If all you want is to turn off the mobile view you can set the user-agent string on the WebView using setUserAgentString (String ua).

Categories

Resources