简体   繁体   中英

Opening files from Google Drive in my Android app by file extension

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>

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM