Open Google Drive file with WebBrowser without show account selector

Having two Google accounts set up on a Android device, opening a Google Drive file (ex. https://drive.google.com/open?id=XXX) with WebBrowser shows a Google account selector.

If I open the same URI in the Samsung browser preinstalled on the device, or in Google Chrome, it doesn’t show the account selector.

How can I open the URI in an external browser or how can I configure ChromeCustomTabs to not display the account selector?

Has anyone else found it? Give me a hint, or something. Thanks in advance, brothers!

Regards,

The account chooser is of Google Drive… I guess that little can be done… Sorry for the turra.

This is based on the shared URL coming from Google Drive. The default shows the account chooser, but you may be able to adjust this behavior by modifying the URL. This link (How to Share Google Drive Files as a URL / Link and Send as a Download) has some explanation on how to adjust a file sharing URL to download a file directly. It might not fit your exact scenario, but there may be something similar you can do with the URL you’re using.

1 Like

@llamaluvr thx for your punctualization, bro; I have solved it by downloading the files from Google Drive through Expo FileSystem attacking the “uc” entry point of Google (https://drive.google.com/uc?id=${link}&export=download).

Then I open the documents with the package “rn-pdf-reader-js” (https://github.com/wiadev/rn-pdf-reader-js/archive/0.2.6.tar.gz) and everything seems to work fluently ^ _ ^

_openFile =  async (title, link, size, extension) => {
  const { t, navigation, connection } = this.props;
  const fileUrl   = `https://drive.google.com/uc?id=${link}&export=download`;
  const filePath  = `${FileSystem.documentDirectory}library/${link}.${extension}`;
  const file      = await FileSystem.getInfoAsync(filePath);
  
  if (!connection && !file.exists) {
    Toast.show({
      type: 'warning',
      position: 'top',
      text: t('library:unavailableDocument'),
      duration: 3000
    });
  }
  else if (file.exists && size == file.size) {
    navigation.navigate('DocumentViewer', { title, uri: filePath });
  }
  else {
    this.setState({ downloading: true });

    FileSystem.downloadAsync(fileUrl, filePath)
      .then(({ uri }) =>  {
        this.setState({ downloading: false });
        navigation.navigate('DocumentViewer', { title, uri });
      })
      .catch((error) => {
        this.setState({ downloading: false });
      });
  }
};

Thx bro…!

Regards,

1 Like

@lya2 Hello - I tried to use FileSystem to download files from google drive and I used the direct download link the same as your post. I got an error: too many redirect. But I paste my link to the browser, the file can be downloaded. Do you have any idea? how do you solve this problem?

Hi @qiyunew,

I use this function to get the source (fileUrl):

_getDownloadLink = (link, extension = 'pdf', isGoogleDriveDoc = false, forcePDF = true) => {
  let format = '';

  if (isGoogleDriveDoc) {
    switch (extension) { 
      case 'docx': 
      case 'doc':
        format = (forcePDF) ? 'pdf' : 'docx';
        return `https://docs.google.com/document/d/${link}/export?format=${format}`;
      case 'xlsx':
      case 'xls':
        format = (forcePDF) ? 'pdf' : 'xlsx';
        return `https://docs.google.com/spreadsheets/d/${link}/export?format=${format}`;
      case 'pptx': 
      case 'ppt': 
        format = (forcePDF) ? 'pdf' : 'pptx';
        return `https://docs.google.com/presentation/d/${link}/export/${format}`;
      default:
        return `https://drive.google.com/uc?id=${link}&export=download`;
    }
  }
  else {
    return `https://drive.google.com/uc?id=${link}&export=download`;
  }
};
const fileUrl = _getDownloadLink(…);

I generate the local destination route (filePath):

const filePath = `${FileSystem.documentDirectory}library/${link}.${fileExtension}`;

And download the file:

FileSystem.downloadAsync(fileUrl, filePath);

I hope it helps you!

Hi @lya2 Thank you very much! I will have a try.