1
votes

So I managed to get my app to open files with a specific extension from file managers, but is it possible for users to tap on the file in Google Drive and have it open in the same way? I mean I know it's possible, other apps do it but what would be the steps to do this? I'm not interested in my app being able to manipulate files on Google Drive in any way, just to have Google Drive "send" the files to my app the way file managers do.

This is the intent filter I'm using now, but it doesn't work for files in Google Drive:

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
            <action android:name="com.google.android.apps.drive.DRIVE_OPEN" />              
    <data android:scheme="file" />
    <data android:mimeType="*/*" />
    <data android:pathPattern=".*\\.xz9" />
    <data android:host="*" />
</intent-filter>
1
Try a content: scheme, for starters. You might also see if there is any particular logging from the Drive app, at the time you request to do something with an .xz9 file, that gives you an idea what the full Uri is, to see if the file extension is on there.CommonsWare
Drive is not mentioned anywhere in the log. Instead it's ActivityManager: START u0 {act=android.intent.action.VIEW cmp=com.google.android.apps.docs/.projector.ProjectorLaunchActivity (has extras)} from uid 10072 on display 0 whatever that means. I don't know what a content: scheme is and a Google search returns something that looks crazy complicated for such a simple action.TimSim
That's launching an internal activity (ProjectorLaunchActivity) of the Google Docs app. Strangely, there is no Uri there, which I had expected. "I don't know what a content: scheme" -- that would be an alternative for file:, http:, https:, etc. It refers to content published by a ContentProvider, which is where everything will be moving in the future.CommonsWare
Ah yes, that thing. I'll look into a content provider tutorial when I have time, but I have no idea why Google Drive will simply not do what every file manager does when you tap on a file.TimSim
As we discussed previously, it is probably using the MIME type, if it knows it. You might consider temporarily adding an <intent-filter> for VIEW, content:, and a MIME type of */*, and see if Drive recognizes you. If so, you can examine the Intent that you get, and then see if you can come up with a more constrained <intent-filter>.CommonsWare

1 Answers

1
votes

I tested it myself for my app. You need to add this intent-filter to your activity so your app can be listed when the user clicks on a file inside the Google Drive app regardless of the file's extension.

<intent-filter>
    <action
        android:name="android.intent.action.VIEW" />

    <action
        android:name="android.intent.action.EDIT" />

    <category
        android:name="android.intent.category.DEFAULT" />

    <category
        android:name="android.intent.category.BROWSABLE" />

    <data
        android:scheme="file" />

    <data
        android:scheme="content" />

    <data
        android:mimeType="application/plain" />

    <data
        android:mimeType="application/octet-stream" />

    <data
        android:mimeType="text/*" />
</intent-filter>