How to disable Gmail add-on on mobile devices? - google-apps-script

I do not want my Gmail add-on to be displayed on mobile devices. How can I disable it for mobile devices?

From the forum, it was stated that this action can't be done as per design. You can comment in this thread.
There's no way to turn that off withing the (unmodified) Gmail UI.
Please use the in-app “Send feedback” link to submit your
request/issue directly to Google. You will not receive a response
from Google.

It is possible to hide the Gmail add-on on mobile devices.
Here is an example code snippet that will make something some up on web only, nothing on android:
function prodd(event) {
if (event.clientPlatform.toUpperCase().equals('WEB')) {
return [getClientInfo(event)];
}
return [];
}
You need to make sure that you use a versioned deployment for this code. On HEAD deployment, it'll show an error: "No add-on data returned. This message is only shown in development mode."

Related

Gmail workspace add-on Mobile app has no back navigation

We have Gmail Workspace add-on that is used on both the Gmail Web app and Gmail Mobile app.
For some reason when running in the Gmail Mobile app there is no back navigation available. The below screen shot shows the navigation on the Web app.
But this is not available on the Mobile app?
I can't see this difference documented anywhere. Is there something we are not setting to enable this?
Also in addition to the back navigation not being available we get an error whenever we try and set the navigation via app script.
For example the following:
cs.newActionResponseBuilder().setNavigation(cs.newNavigation().popCard()).build()
gives the error on Mobile app only -
failed to complete your action because the add-on will be in a bad
state
Is this behaviour to be expected? Is there some other approach to controlling navigation on Gmail Mobile that we are not aware of?
I found the problem... In case somebody else experiences it.
In my code - the issue is caused when an invoked function returns a card as in the following snippet
function loadStackCard() {
var emailCard = CardService.newCardBuilder().setHeader(CardService.newCardHeader().setTitle('STACK CARD'))
.addSection(CardService.newCardSection().addWidget(CardService.newTextButton().setText('GO BACK')
.setOnClickAction(CardService.newAction().setFunctionName('goBack')))).build();
return emailCard;
}
But when I push the card onto the navigation stack it works on Mobile
function loadStackCard() {
var emailCard = CardService.newCardBuilder().setHeader(CardService.newCardHeader().setTitle('STACK CARD'))
.addSection(CardService.newCardSection().addWidget(CardService.newTextButton().setText('GO BACK')
.setOnClickAction(CardService.newAction().setFunctionName('goBack')))).build();
nav = CardService.newNavigation().pushCard(emailCard) ;
return CardService.newActionResponseBuilder().setNavigation(nav).build();
}

How to force links sent by email to open in user's browser instead of gmail in-app browser

I have a website that is JavaScript-heavy and requires user to record their videos, When I send my emails to my customers the link opens in gmail's in-app browser which you cannot record from, Plus there's many functionalities missing.
How to trigger a popup when user clicks the links in the email to select whatever browser they wants instead of gmail's in-app one? I've seen some people do that I tried and did some research for it but not results.
By default a web browsers cannot open a rival's web browser. This would be a security risk. There are hacks which involve the user downloading an add-on or extension. See answer in stackoverflow.com/questions/10070744/open-ie-browser-in-firefox-chrome-page
The popup you're referring to are most likely apps. The user would have to granted permission. (This I don't have experience with).
It looks like there is no way to programmatically force emails on Android to open in Chrome browser. The user has to alter their system settings. Therefore, an alternative approach may be to educate the user (about the loss of functionality). This can be done by preforming browser sniffing & displaying an appropriate message at the top of the webpage.
With JavaScript, you can test if a function is supported & enabled by creating functions. Below is an example, which determine is LocalStorage is available. (It's only for illustration purposes).
function isLocalStorageEnabled(){
var test = 'test';
try {
localStorage.setItem(test, test);
localStorage.removeItem(test);
return true;
} catch(e) {
return false;
}
}
if(isLocalStorageEnabled() === true){
// available
}else{
// unavailable
}
Also I believe there is no single way to detect if the user, is using Gmails built-in browser or Chrome. However based on the following factors, you can assume they're using Gmail if:
User has clicked an email link. (You can append a query string. On landing on site, store in session and redirect without the append query string).
User is on android (/Android/.test(window.navigator.userAgent)).
User is on Chrome (see answer stackoverflow.com/questions/4565112/javascript-how-to-find-out-if-the-user-browser-is-chrome/13348618#13348618).
The web browser doesn't support some sort of JavaScript function, which works on Chrome but not on Gmails browser.
If all criteria are true, then you can then display a message like: For full functionality, please use Chrome or alternatively in Gmail: Go to Settings, General, and uncheck the option to open links in gmail (and reopen link from Gmail).
Note: browser detection can be faked. However this should be fine for displaying messages.
The option to send links in the Gmail (or any app) WebView to the system handler is reserved for the app itself.
The implementation for apps is described here:
WKWebView open links from certain domain in safari
WebView link click open default browser
However, if you instruct the recipient to long press the link in the email, there is an option to open the link in browser and that will take them to the default browser.

Chrome Allow or snooze all Notifications

I plan to implement a do not disturb mode in Chrome as an extension/Chrome app but I don't know if Chrome offers any API to toggle notifications or somehow manage extensions e.g. in the following screenshot
So basically, I'm hoping Chrome provides a global method to snooze notifications or somehow offers some APIs with which exceptions can be managed and I could simply one by one Block all sites when do not disturb is desired and toggle back on when it needs to be turned off. Any leads?
Take a look at chrome.contentSettings,
chrome.contentSettings.notifications.set({
primaryPattern: '<all_urls>',
setting: 'block'
});

How to use FastButtons for them to work on mobile devices?

I have read this (and other relating things also):
https://developers.google.com/mobile/articles/fast_buttons?hl=fi#conclusion
but I don't understand how to use this in Google Apps Script. I made the UI with GUI Builder and now I want the buttons to work also on mobile devices.
Could someone please explain to me with a code example of how to change my buttons to work also on mobile devices?
Code that works Ok on PC but not on mobile device:
var handler109 = app.createServerClickHandler('func109');
var but109 = app.getElementById('Button109');
but109.addClickHandler(handler109);
How to use Client Handler? app.createClientHandler('func109') generates an error, app.createClientClickHandler('func109') generates an error... How do I define that function func109 should be called?
var handler109 = app.createClientHandler();
var but109 = app.getElementById('Button109');
but109.addClickHandler(handler109);
First, the article you've shared is applicable for mobile and not so much for Google Apps Scripts.
However, the buttons you make in Google Apps Script WILL work on mobile devices too. However, if you only have a server handler set up on the button, it will take a noticeable period of time before the action of the button is seen by the user.
Google Apps Script also has client handlers which you can use which show up a much faster response than server handlers.
Issue 1086 might be relevant in your case

Gmail extension/gadget API - how to add a button to the compose toolbar?

I'm trying to figure out how can I add a button to the Gmail compose window.
In "Gmail Labs" they have some extensions that add certain buttons For example "Send & Archive" button and "Inserting images" button, so I assume this is possible.
I checked their API here and it seems that you can either add a gadget to left sidebar or use contextual gadgets that are dependent on the message context. I'm looking for a way to add a button to the toolbar of the compose window, and both options don't seem to support it.
Do you know how can this be done?
If it's not possible using Gmail API, is there another way I can achieve this? Maybe by creating a Google Chrome extension or user scripts?
I would appreciate any info that can direct me in the right direction.
Thanks.
The Gmail Labs have special permissions because they are written by Google Employees, unfortunately we mortals don't have such power. There is a way around it of course and you've correctly pointed out that it is to make a Chrome Extension or a UserScript. If you choose to do a Chrome Extension it will just be a wrapper for a UserScript anyway
You will have to create and inject the button programmatically. This will involve quite a bit of scouring the Gmail source code (spoiler: it's ugly).
Without more details about what you want to do, I won't be able to provide much more help but I can help you with one problem right away. You have to make your script wait until the Gmail loading process is done which is a bit of a challenge. This is the solution I'm currently using in Minimalist:
function bootstrap() {
target = document.querySelectorAll('.vt:not(.SFzvCe)');
if (document.querySelectorAll('html.xiu1Fc, html.aao')[0] == null) {
return;
}
if (target.length > 0) {
// loaded, do stuff
} else {
window.setTimeout(bootstrap, 200);
}
}
window.addEventListener('DOMSubtreeModified', bootstrap);
That version waits for the chat to fully load. Let me know if you have any other questions: #anstosa
You can use InboxSDK for that.
Here is documentation link
Also you have a Hello world repo, where is a solved your problem
hello repo