Hide / Disable default menu in Chrome Custom Tab - android

I have implemented new Chrome Custom Tab in android, I am using the following code to open
String url = "http://www.flipkart.com/";
int color = Color.BLUE;
CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
intentBuilder.setToolbarColor(color);
intentBuilder.setShowTitle(true);
CustomTabActivityHelper.openCustomTab(
this, intentBuilder.build(), Uri.parse(url), new WebviewFallback());
I need to secure my URL or not like to show my URL to User, But there is a option Open in Chrome in default menu, By using this link user can open my URL in browser,By how hide the default menu?

At this moment, it's not possible to hide the overflow menu or "Open in Chrome" menu item.

There are no methods for hiding the menu option in Chrome custom tabs

Chrome Custom Tab actually uses Chrome app in user's mobile.
start activity in Chrome app by link, If chrome not installed on the user's mobile, it will use a webView as the default.
In fact, Chrome Custom Tabs is designed to display a web page where the user is sure that the programmer of that software does not have a phishing, Like a bank payment.
Therefore, you must show the options in the toolbar to the user.

This can be hide by using app link assistant.
complete guideline for how to create app link can be found here.
https://developer.android.com/studio/write/app-link-indexing
after successful generation and verification the above header can be hidden.
I have implemented this and result is like

You must add hiding flag before. To disable your URL parameter but it can't hide your site name.
intentBuilder.enableUrlBarHiding();

Related

Web on mobile - Open URLs in full browser apps when navigating from Chrome Custom Tabs or Safari ViewController

I have a web page that is often launched from inside an Android/iOS app in their respective "tab system", Chrome Custom Tabs / SFSafariViewController.
The requirement I have is to have some urls redirect and open in the full browser app instead of navigating in the tab/controller.
I tried adding to one of those URLs the href target="_blank" or use window.open()` but in Android at least that opens a custom tab inside of the existing tab. Haven't had the chance to test that on iOS as of yet but I have the sneaking suspicion it will do nothing as the Safari View Controller does not support windows.
Any ideas on how I can force these 2 tools to open a url in the full apps would be much appreciated.
Thanks.
For people who might come across this and are interested.
Unfortunately it is not possible to force the in app browser to open a new tab in the full version of it. Like I mention in he question iOS simply can't do that due to the nature of the SFSafariViewController, while in Android it does not work... for reasons I guess, could not find something concrete and I will not go into speculating the reasons.
The solution I ended up using on my side is:
Have the site send a deep link to the app with the URL that should it should open externally, the app then closes the in app browser and launches the receive URL to the full browser.
I am setting this as the answer for now. If anyone comes with a better solution or an immediate solution to the problem, I am more than happy to change it.
Cheers
Twitter and whatsapp open webpages in CCT and SVC, but FB messenger doesn't, because it opens in its in-app-browser (IAB), unless you change your phone settings.
But. I found this javascript which works for me, for safari on iphone and chrome on android. Put it in the beginning of your index page at the end of your header and refer to this same index page.
Of course change yourwebpagetoopenoutsidewbhere to your own page.
var standalone = window.navigator.standalone,
userAgent = window.navigator.userAgent.toLowerCase(),
safari = /safari/.test(userAgent),
ios = /iphone|ipod|ipad/.test(userAgent);
var qq;
if (ios) {
if (!standalone && safari) {
// Safari
} else if (!standalone && !safari) {
// iOS webview
s=location.toString().split('?');s=s[1];
qq="https://www.yourwebpagetoopenoutsidewbhere.com/index.php?" + s;
window.close(); // Close the empty view window
window.open(qq,'_system', 'location=yes', replace);
}
} else {
if (userAgent.includes('wv')) {
// Android webview
s=location.toString().split('?');s=s[1];
qq="https://www.yourwebpagetoopenoutsidewbhere.com/index.php?" + s;
window.close(); // Close the empty view window
var winloc = 'intent:' + qq + '#Intent;end';
window.location = winloc;
} else {
// Chrome
}
}

Force open link in new background tab (Android firefox)

Goal: From a website having a lot of links, I will usually middle click the ones I want. Firefox will open them in background new tabs on the side. Now I want to do the same from my Android tablet where middle click is not available.
1) Best: Is there an easy way to middle click on a tablet ?
2) Otherwise something better than a long press to simulate right click then open in new tab ?
3) I'm currently trying a TamperMonkey solution based on other questions found here:
link.addEventListener('click', function(event){event.preventDefault();return newBackgroundTab(this);}, false);
function newBackgroundTab(node) {
var newWindow = window.open("about:blank", "_blank");
newWindow.blur();
window.focus();
newWindow.location.href = node.href;
return false;
}
It also need to set the dom.disable_window_flip option to false in Firefox.
This works on desktop, but not on Android, focus stays on the new tab even though the disable option was already on false by default.

Android IMA SDK "Learn More" custom click listener

Upon tapping on "Learn More" text-link when a Video-Ad is played in the Android App, a default "Open With" dialog appears before the appropriate ClickThroughUrl is retrieved in the AdEvent.AdEventListener.onAdEvent(AdEvent adEvent) method and passed along to Custom Chrome Tabs.
Therefore, after closing the Custom Chrome Tabs, the dialog still remains.
Is there a way to customize the "Learn More" text-link so the Click-event goes straight to the AdEventListener rather than handling on it's own thereby showing the "Open With" dialog.
In other words, I don't want a "Open With" dialog when I click on "Learn More" text-link in a Video-Playback Android App while a Video-Ad is playing. Any pointers how to achieve that will be appreciated.
Well, you could theoretically extract the URL via reflection
try {
Method method = ad.getClass().getDeclaredMethod("getClickThruUrl");
Url clickUrl = (String) method.invoke(ad);
} catch (Exception e) {
// Log or whatever
}
And then open a pre-selected browser yourself, maybe via an Intent that knows the package name of the one you have in mind?
But yeah... those are two pretty hacky things directly in a row, and they're both likely to break in future, when method names change, packages come and go, users have new browsers etc. So you'll have to think about this

How to do a colored address bar in Chrome for Android like thenextweb.com

When you are visiting thenextweb.com with an Android Chrome Browser, you will see a red address bar. Is there a trick to do this?
<meta name="theme-color" content="#db5945">
You can refer following site that may help you get colored address bar:
How to change the color of header bar and address bar in newest Android Chrome version on Lollipop?
Android introduced in-app browser webviews called Chrome CustomTabs. which is similar to launching intent for web browser.
You can specify the color for addressbar while passing url .
private static final String EXTRA_CUSTOM_TABS_TOOLBAR_COLOR = "android.support.customtabs.extra.TOOLBAR_COLOR";
intent.putExtra(EXTRA_CUSTOM_TABS_TOOLBAR_COLOR, colorInt);
for more details. please read.
https://developer.chrome.com/multidevice/android/customtabs

How to add android bookmark on homescreen from web page?

I'm new to web applications for Android..
How can you add a bookmark on the home screen from a web page using Javascript from the click of a button?
If we make an easy way for users to bookmark pages, they will show some interest in bookmarking them. This is one of the requirement for my projects.
How can this be done?
Some of the people answering here seem to not understand that you want something for mobile, not IE, Firefox, etc. They also don't seem to read very well where you said "website", not "mobile app". However, I believe I have read your question properly.
There's extremely high odds that you'll probably also want this for iPhone, so I'll answer this for iPhone and Android as well.
For iPhone, it's as simple as using this script:
http://code.google.com/p/mobile-bookmark-bubble/
For Android, it's not so pretty, unfortunately. You'll have to make a button or hyperlink that redirects to an instructions page on your site. The instructions will tell web visitors to do "Settings > More > Add Shortcut to Home" and hope they "get it".
One option for Android is that you can fork mobile-bookmark-bubble, make it load at the bottom of the page without the bottom triangle, and make it read, "Click the Settings button > More > Add Shortcut to Home". As well, you might want to put the 2 bars icon of what the Settings button looks like right next to "Settings button".
As for how to customize the icon that gets created, I'm still researching that and will update this answer when I find out.
Here is a possible workaround, and while it isn't exactly what you want, I think it is the easiest solution as I'm highly skeptical that android allows web pages to automatically issue intents to a device, as this would be a potential security problem. Someone please correct me if I'm wrong
I recommend that you create an app that is simply a wrapper around a bookmark. When the user clicks on your app, your app creates an intent that simply opens the device's default web browser to your page. While this will require the users install a app it has a few advantages over a plain bookmark. You will be able to track how many people have your app/bookmark installed, how often they use it etc. You can also provide a nice looking icon instead of using the stock "bookmark" icon.
Upload the app to the market as a free app and place a "bookmark this" link on your webpage that simply directs the user to download your free app.
You can create a web page shortcut on home screen using this code. Provide the necessary info like url, title etc..
final Intent in = new Intent();
final Intent shortcutIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
long urlHash = url.hashCode();
long uniqueId = (urlHash << 32) | shortcutIntent.hashCode();
shortcutIntent.putExtra(Browser.EXTRA_APPLICATION_ID, Long.toString(uniqueId));
in.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
in.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
in.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(
BrowserBookmarksPage.this,
R.drawable.ic_launcher_shortcut_browser_bookmark));
in.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
//or in.setAction(Intent.ACTION_CREATE_SHORTCUT);
sendBroadcast(in);
Update
The browser does not recognise the intent scheme, so there is no way you can add a shortcut to your webpage from your webpage.
This can help
<script language="javascript" type="text/javascript">
$(document).ready(function(){
$("a.jQueryBookmark").click(function(e){
e.preventDefault(); // this will prevent the anchor tag from going the user off to the link
var bookmarkUrl = this.href;
var bookmarkTitle = this.title;
if (window.sidebar) { // For Mozilla Firefox Bookmark
window.sidebar.addPanel(bookmarkTitle, bookmarkUrl,"");
} else if( window.external || document.all) { // For IE Favorite
window.external.AddFavorite( bookmarkUrl, bookmarkTitle);
} else if(window.opera) { // For Opera Browsers
$("a.jQueryBookmark").attr("href",bookmarkUrl);
$("a.jQueryBookmark").attr("title",bookmarkTitle);
$("a.jQueryBookmark").attr("rel","sidebar");
} else { // for other browsers which does not support
alert('Your browser does not support this bookmark action');
return false;
}
});
});
</script>
<h2>Click on the respective links below to bookmark the same</h2>
DeveloperSnippets, Tech Video Bytes, Witty Sparks, Snehah.com
For more info, go to this link ( http://www.developersnippets.com/2009/05/10/simple-bookmark-script-using-jquery/)

Categories

Resources