views:

289

answers:

1

Can someone explain me how I would be able to imitate the default browser when trying to download .apk from the net?

So far I have this:

WebView webview;

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

        webview = (WebView) findViewById(R.id.webview);
        webview.setWebViewClient(new HelloWebViewClient());
        WebSettings webSettings = webview.getSettings();
        webSettings.setSavePassword(false);
        webSettings.setSaveFormData(false);
        webSettings.setJavaScriptEnabled(true);
        webSettings.setSupportZoom(false);

        webview.setDownloadListener(new DownloadListener() {
            public void onDownloadStart(final String url, String userAgent,
            String contentDisposition, String mimetype,
            long contentLength) {
            Toast.makeText(testapp.this, url, Toast.LENGTH_LONG);
            }
            });

        webview.loadUrl("http://dacp.jsharkey.org/TunesRemote-r2.apk");       

        }

I've already added the permission to use the internet. Are there any other permissions that I need to add? Am I doing the DownloadListener incorrectly?

Thank you in advance!

+1  A: 

Use an Intent

Intent intent = new Intent(Intent.ACTION_VIEW ,Uri.parse("http://dacp.jsharkey.org/TunesRemote-r2.apk"));
startActivity(intent);    
Jorgesys
Awesome thank you! It worked! I've also found another way using using URLConnection, BufferedInputStream, and BufferedOutputStream. Could you tell me the difference between using this method I found and the one you suggested? Thanks again!
Zack