views:

54

answers:

2

Hi all I need some help here I have gone through the tutorial for WebView and I get it to load my url and it loads fine. I run a site that offers .pkg files to my users for download to there device. The issue is instead of downloading the .pkg file it just displays the raw code of the .pkg file in the webview. How can I get this to force download to the root of the sd card? Here is what I have

package com.ps3brew.view;

import com.ps3brew.view.R;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class WebViewExample extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        WebView webView = (WebView) findViewById(R.id.webview);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.loadUrl("http://www.myurl.com/phone.html");

        webView.setWebViewClient(new HelloWebViewClient());

    }
}

Any help would be great I am 100% new to this android dev and im just stuck everything I have tried has failed any help would be great. Thanks in advance

A: 

What happens if you long-click the link? Can you download it that way?
You might want to consider scraping the links and designing a GUI with a list instead of simply sending the user to the full website.

BlackDragonBE
Ok so I should have stated before that in the normal browser it does the exact same by showing the raw code and in my app nothing happens on the long-click. also upon clicking a .zip link nothing happens either. I was after the idea of click the link and it auto downloads the file. And the files I offer for download have nothing to do with android or phones at all the .pkg file is for a different device all together but you can use your phone as a storage device so im just trying to cut out the computer out of the process.
TwitcH
Also you say to use a list that would be awesome to do is there any where you can point me to make this happen? I am real new to android and the dev docs are horrible with real examples to learn from. I basically need 1st screen to be a 3 or 4 list that then opens a new list of actual files then when you click a file either just download it or go to a description with option to download. I would have to update the app with every new file added or is there a better way?
TwitcH
If it's your own website you can make a txt or xml file to get the links. If it's not or you want the automatic way, you can use XPATH to get the links out of the <a href> elements of the HTML of the page. (See this: http://thinkandroid.wordpress.com/2010/01/05/using-xpath-and-html-cleaner-to-parse-html-xml/) You can make a list using this tutorial: http://www.androidpeople.com/android-listview-onclick/ Happy coding!
BlackDragonBE
Hey thanks for responding I have gone the route of a list updating from xml from the web and it looks to be a way better way to do this Thanks
TwitcH
Any chance you know of any code to do what I asked cistearns above? about code to get the url either from the xml or the AppUrl that gets set from each xml entery?
TwitcH
This article lists several options for parsing XML: http://www.ibm.com/developerworks/opensource/library/x-android/index.html
BlackDragonBE
A: 

I would verify that your html page works in the normal android browser first. My guess is that the MIME type for apk's on your server are incorrect.

The MIME type should be application/vnd.android.package-archive

In addition users will need to set the phone system preferences to allow installation of non-Market applications.

cistearns
file type is .pkg not .apk these are not files for the phone to run and it does the same thing in the normal browser just shows the raw code.
TwitcH
I that case you will need to handle downloading/saving yourself. As far as I have seen Android doesn't handle arbitrary file types. There are special handlers for know MIME types like images and audio, but for something arbitrary you need to do your own thing.You can make your own handler to support the MIME type of the file you want to handle that will save the data, but at that point you may be better off moving away from WebView and instead going to xml and ListViews that allow selection of files to download.
cistearns
Hey thanks for responding I went ahead and scrapped the first app and not I made a updating listview from a xml file on my site but now I need to know how to make the download button grab the URL from the xml file or from the AppUrl set from the xml in the app itself. any thoughts on that?
TwitcH