0

I am currently building an Android app using HTML5. Inside my app, I am providing link to a HTML file available inside tomcat server on my machine.

<div><a href="http://localhost:8082/directDownload/sample.html">Beep</a></div> 

The HTML file "sample.html" has link to download a file in same file location, where the sample.html is placed.

sample.html has this --> <a href="MyFirstOnMosync.apk">Click to download</a>

The problem here is, when I run my app on an android mobile, the link stays dumb and it won't initiate the download from the given path.

But, the same URL when I open in a web browser, the download starts.

Could anyone let me know why this URL is not initiating the download inside my app?? I already enabled "Allow installation of non-Market applications" in the settings of my android device.

Lohith Korupolu
  • 1,066
  • 1
  • 18
  • 52

2 Answers2

0

Use 10.0.2.2 as IP for server running on the same machine as the Android emulator.

Check out following post with similar problem:

Download File inside WebView

Check out this link for setting up the mime type in tomcat.

Copied for reference:

In Tomcat 5.x and 4.x, the default mappings between MIME types and file extensions are stored in the file tomcat_home/conf/web.xml, where tomcat_home is the path under which Tomcat was installed on your server. The mappings specified there are applied to all web / WAP applications hosted on your Tomcat server. Application-specific mappings should be set in the WEB-INF/web.xml file under the directory of your web / WAP application.

Each mapping is specified with the <mime-mapping>, <extension> and <mime-type> tags. Here is an example:

<web-app>

...

  <mime-mapping>
    <extension>xhtml</extension>
    <mime-type>application/vnd.wap.xhtml+xml</mime-type>   </mime-mapping>

  <mime-mapping>
    <extension>wml</extension>
    <mime-type>text/vnd.wap.wml</mime-type>   </mime-mapping>

  <mime-mapping>
    <extension>wmls</extension>
    <mime-type>text/vnd.wap.wmlscript</mime-type>   </mime-mapping>

  <mime-mapping>
    <extension>wbmp</extension>
    <mime-type>image/vnd.wap.wbmp</mime-type>   </mime-mapping>

...

</web-app>
Community
  • 1
  • 1
Praful Bhatnagar
  • 7,425
  • 2
  • 36
  • 44
  • thanks for the reply Praful bhatnagar - no, this did not work :( – Lohith Korupolu Nov 21 '12 at 08:48
  • Praful I added mime type to the web.xml file but with no success. here is what I added - apk application/vnd.android.package-archive – Lohith Korupolu Nov 21 '12 at 10:07
  • also, the link you gave (download file inside webview) was not helpful to me as i am using only HTML5 – Lohith Korupolu Nov 21 '12 at 10:08
  • ohh sorry i thought you were using something like phoengap that runs in webview... – Praful Bhatnagar Nov 21 '12 at 10:10
  • I am sorry too.. I mentioned phonegap, but there also I just used HTML5. I am not aware of the other ways :( – Lohith Korupolu Nov 21 '12 at 10:12
  • this link excellently works on a web-browser but playing around with me, as an android app – Lohith Korupolu Nov 21 '12 at 10:13
  • bit confused... is it a phonegap app or web app hosted on web server... if its a phonegap app then phonegap app runs in webview so you might need `DownloadListener`.. – Praful Bhatnagar Nov 21 '12 at 10:20
  • am sorry Praful, if I confused you. I stopped working on phonegap for this, and currently executing the whole stuff on a tool called Mosync. here it's completely on HTML5 and javascript. – Lohith Korupolu Nov 21 '12 at 12:34
  • dont know much about Mosync.. if it creates an apk from javascript and html then there are high chances that it is getting executed in web view.. sicne native app bundled as apk can only execute html and java script in webview (unless they have created there own webview kind of UI widget).. and as i shared in my answer it looks like you have to use `DownloadListner` for downloading file from the webview.... – Praful Bhatnagar Nov 21 '12 at 12:49
  • no Praful, they do not have webview kind UI widget... I tried to understand their concept, they are just creating an apk from JS and HTML. jquery is also allowed here. do u have any idea, how to get access to a phone's browser with code inside an app? using JS? Is this actually possible from a native android app? if yes, i will try working out with the JS... – Lohith Korupolu Nov 22 '12 at 07:29
  • sorry for enforcing the same point again.. But in android you can only execute java script and html either in browser if the app is web app or in web view if the js+html is bundled as the native app (apk file).. – Praful Bhatnagar Nov 22 '12 at 07:48
  • sorry to bother u Praful. thanks for ur help. I will see if I can do my stuff completely as a webapp.. – Lohith Korupolu Nov 22 '12 at 08:33
0

If you are using real device you must set your url with static ip of your machine like 192.168.0.10 and in emulator 10.0.0.2

See this post.

Community
  • 1
  • 1
Misagh Aghakhani
  • 1,023
  • 2
  • 13
  • 29