I’m working on an Android app that has a sharing function. When users want to share files, I show them a list of apps they can use. Here’s my current code:
The problem is that while apps like Gmail and Dropbox show up in the chooser dialog, Google Docs doesn’t appear. However, I noticed that other similar apps on the Play Store do show Google Docs as an option for the same file type. What am I missing? Do I need to change the intent type or use a different approach to include Google Docs in the sharing options?
You’re hitting this because you’re using the old file:// URI scheme. Google Docs and most modern apps won’t accept those anymore - they need FileProvider URIs for security reasons. Here’s what you need to do: Set up a FileProvider in your AndroidManifest.xml with the right file paths, then switch your code to use FileProvider.getUriForFile() instead. Make sure you add the FLAG_GRANT_READ_URI_PERMISSION flag to your intent too. I’ve run into this exact problem before and this fix worked perfectly, especially with Google apps since they’re pretty strict about security.
Your MIME type is probably the culprit. Google Docs is picky about what file types it’ll accept through intents. Don’t hardcode application/zip - try */* or use the actual MIME type of your content instead. I ran into this same thing when sharing documents. Google Docs filtered out my shares because the MIME type didn’t match what it expected. You can use getMimeTypeFromExtension() to grab the right MIME type automatically. Also, apps like Google Docs only show up in the share menu when they can actually handle your content. Make sure your file is something Google Docs can process. Test with a simple text file first - that’ll tell you if this is what’s causing the problem.
try adding both FLAG_GRANT_READ_URI_PERMISSION and FLAG_GRANT_WRITE_URI_PERMISSION to your intent. Google Docs might require write permissions, even for just sharing. also, double-check your targetSdkVersion; newer Google apps can be finicky with older API levels.