How do I permit the android browser to download fi

2020-04-11 20:23发布

I want to have the default android browser be able to download files of a particular file extension, .xyz, for example.

Without installing Astro (or some other file manager), users will get the error "Cannot download. The content is not supported on this phone". Installing the Astro application allows the android browser to download any file to the sdcard.

How does it do that? I don't want users of my app to have to download Astro, but rather, just let the OS or browser know that it's okay to download files with the extension .xyz, because my app will handle them.

1条回答
够拽才男人
2楼-- · 2020-04-11 21:20

Add the appropriate entries to the manifest for you to respond to ACTION_VIEW Intents for that type of file. For example, this filter is for an activity that can view PDF files:

        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:mimeType="application/pdf" />
        </intent-filter>

With an appropriate <data> element, you could literally watch for .xyz files, though I think it will be better if you can watch for a MIME type instead.

查看更多
登录 后发表回答