Android: Download file directly from browser

寵の児 提交于 2020-01-01 06:39:33

问题


I'm trying to make the android browser download a file of a specific type '.xxx’ say, so that I can then set an app to be associated with it.

I've successfully done the association part, in that I've made it so that clicking on a file of the right type in an explorer app loads the appropriate app. I expected this to carry over to the browser so that if I attempted to download a file type .xxx then it would open the app.

This doesn’t happen, all that happens is that the text contained in the file is displayed in the browser. I've set up a mime type link for this in astro (application/xxxx) but this has made no difference either. It must be possible to do what I want because If I click on a pdf file for instance the browser downloads it and gives me the option to open a pdf reader.


回答1:


You need to add an <intent-filter> tag within a <receiver> tag in your Application Manifest.

How this works is the following:

  1. Android broadcasts an intent

  2. The system searches a list of applications capable of receiving that intent

  3. The system queries the user to select an application to handle that intent

  4. The user selects an application, or is defaulted to a pre-specified application

  5. The application opens

Take a look at the receiver element docs to see more details about how to implement this.

Holler if you need more help.

Thanks




回答2:


Android applications define which 'file types' they support in their respective manifest files. If your app isn't loading when the browser calls it then maybe there is something missing in your manifest? What happens in the simulator?

http://developer.android.com/guide/topics/manifest/manifest-intro.html




回答3:


All mime you can you for Android : link



来源:https://stackoverflow.com/questions/7968591/android-download-file-directly-from-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!